本文整理汇总了Java中org.bitcoinj.signers.TransactionSigner类的典型用法代码示例。如果您正苦于以下问题:Java TransactionSigner类的具体用法?Java TransactionSigner怎么用?Java TransactionSigner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TransactionSigner类属于org.bitcoinj.signers包,在下文中一共展示了TransactionSigner类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Wallet
import org.bitcoinj.signers.TransactionSigner; //导入依赖的package包/类
/** For internal use only. */
public Wallet(NetworkParameters params, KeyChainGroup keyChainGroup) {
this.params = checkNotNull(params);
this.keychain = checkNotNull(keyChainGroup);
if (params == UnitTestParams.get())
this.keychain.setLookaheadSize(5); // Cut down excess computation for unit tests.
// If this keychain was created fresh just now (new wallet), make HD so a backup can be made immediately
// without having to call current/freshReceiveKey. If there are already keys in the chain of any kind then
// we're probably being deserialized so leave things alone: the API user can upgrade later.
if (this.keychain.numKeys() == 0)
this.keychain.createAndActivateNewHDChain();
watchedScripts = Sets.newHashSet();
unspent = new HashMap<Sha256Hash, Transaction>();
spent = new HashMap<Sha256Hash, Transaction>();
pending = new HashMap<Sha256Hash, Transaction>();
dead = new HashMap<Sha256Hash, Transaction>();
transactions = new HashMap<Sha256Hash, Transaction>();
eventListeners = new CopyOnWriteArrayList<ListenerRegistration<WalletEventListener>>();
extensions = new HashMap<String, WalletExtension>();
// Use a linked hash map to ensure ordering of event listeners is correct.
confidenceChanged = new LinkedHashMap<Transaction, TransactionConfidence.Listener.ChangeReason>();
signers = new ArrayList<TransactionSigner>();
addTransactionSigner(new LocalTransactionSigner());
createTransientState();
}
示例2: completeTxPartiallySignedMarriedThrowsByDefault
import org.bitcoinj.signers.TransactionSigner; //导入依赖的package包/类
@Test (expected = TransactionSigner.MissingSignatureException.class)
public void completeTxPartiallySignedMarriedThrowsByDefault() throws Exception {
createMarriedWallet(2, 2, false);
myAddress = wallet.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, COIN, myAddress);
SendRequest req = SendRequest.emptyWallet(OTHER_ADDRESS);
wallet.completeTx(req);
}
示例3: transactionSignersShouldBeSerializedAlongWithWallet
import org.bitcoinj.signers.TransactionSigner; //导入依赖的package包/类
@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());
}
示例4: addTransactionSigner
import org.bitcoinj.signers.TransactionSigner; //导入依赖的package包/类
/**
* <p>Adds given transaction signer to the list of signers. It will be added to the end of the signers list, so if
* this wallet already has some signers added, given signer will be executed after all of them.</p>
* <p>Transaction signer should be fully initialized before adding to the wallet, otherwise {@link IllegalStateException}
* will be thrown</p>
*/
public void addTransactionSigner(TransactionSigner signer) {
lock.lock();
try {
if (signer.isReady())
signers.add(signer);
else
throw new IllegalStateException("Signer instance is not ready to be added into Wallet: " + signer.getClass());
} finally {
lock.unlock();
}
}
示例5: getTransactionSigners
import org.bitcoinj.signers.TransactionSigner; //导入依赖的package包/类
public List<TransactionSigner> getTransactionSigners() {
lock.lock();
try {
return ImmutableList.copyOf(signers);
} finally {
lock.unlock();
}
}
示例6: completeTxPartiallySignedMarriedThrowsByDefault
import org.bitcoinj.signers.TransactionSigner; //导入依赖的package包/类
@Test (expected = TransactionSigner.MissingSignatureException.class)
public void completeTxPartiallySignedMarriedThrowsByDefault() throws Exception {
createMarriedWallet(2, 2, false);
myAddress = wallet.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);
sendMoneyToWallet(wallet, COIN, myAddress, AbstractBlockChain.NewBlockType.BEST_CHAIN);
Wallet.SendRequest req = Wallet.SendRequest.emptyWallet(new ECKey().toAddress(params));
wallet.completeTx(req);
}
示例7: transactionSignersShouldBeSerializedAlongWithWallet
import org.bitcoinj.signers.TransactionSigner; //导入依赖的package包/类
@Test
public void transactionSignersShouldBeSerializedAlongWithWallet() throws Exception {
TransactionSigner signer = new NopTransactionSigner(true);
wallet.addTransactionSigner(signer);
assertEquals(2, wallet.getTransactionSigners().size());
Protos.Wallet protos = new WalletProtobufSerializer().walletToProto(wallet);
wallet = new WalletProtobufSerializer().readWallet(params, null, protos);
assertEquals(2, wallet.getTransactionSigners().size());
assertTrue(wallet.getTransactionSigners().get(1).isReady());
}
示例8: printTransactionSigners
import org.bitcoinj.signers.TransactionSigner; //导入依赖的package包/类
public String printTransactionSigners(List<TransactionSigner> signers) {
StringBuilder out = new StringBuilder();
out.append("TransactionSigner Info: \n");
for (TransactionSigner signer : signers){
out.append(" -").append(signer.toString()).append("\n");
}
return out.toString();
}
示例9: walletToProto
import org.bitcoinj.signers.TransactionSigner; //导入依赖的package包/类
/**
* Converts the given wallet to the object representation of the protocol buffers. This can be modified, or
* additional data fields set, before serialization takes place.
*/
public Protos.Wallet walletToProto(Wallet wallet) {
Protos.Wallet.Builder walletBuilder = Protos.Wallet.newBuilder();
walletBuilder.setNetworkIdentifier(wallet.getNetworkParameters().getId());
if (wallet.getDescription() != null) {
walletBuilder.setDescription(wallet.getDescription());
}
for (WalletTransaction wtx : wallet.getWalletTransactions()) {
Protos.Transaction txProto = makeTxProto(wtx);
walletBuilder.addTransaction(txProto);
}
walletBuilder.addAllKey(wallet.serializeKeyChainGroupToProtobuf());
for (Script script : wallet.getWatchedScripts()) {
Protos.Script protoScript =
Protos.Script.newBuilder()
.setProgram(ByteString.copyFrom(script.getProgram()))
.setCreationTimestamp(script.getCreationTimeSeconds() * 1000)
.build();
walletBuilder.addWatchedScript(protoScript);
}
// Populate the lastSeenBlockHash field.
Sha256Hash lastSeenBlockHash = wallet.getLastBlockSeenHash();
if (lastSeenBlockHash != null) {
walletBuilder.setLastSeenBlockHash(hashToByteString(lastSeenBlockHash));
walletBuilder.setLastSeenBlockHeight(wallet.getLastBlockSeenHeight());
}
if (wallet.getLastBlockSeenTimeSecs() > 0)
walletBuilder.setLastSeenBlockTimeSecs(wallet.getLastBlockSeenTimeSecs());
// Populate the scrypt parameters.
KeyCrypter keyCrypter = wallet.getKeyCrypter();
if (keyCrypter == null) {
// The wallet is unencrypted.
walletBuilder.setEncryptionType(EncryptionType.UNENCRYPTED);
} else {
// The wallet is encrypted.
walletBuilder.setEncryptionType(keyCrypter.getUnderstoodEncryptionType());
if (keyCrypter instanceof KeyCrypterScrypt) {
KeyCrypterScrypt keyCrypterScrypt = (KeyCrypterScrypt) keyCrypter;
walletBuilder.setEncryptionParameters(keyCrypterScrypt.getScryptParameters());
} else {
// Some other form of encryption has been specified that we do not know how to persist.
throw new RuntimeException("The wallet has encryption of type '" + keyCrypter.getUnderstoodEncryptionType() + "' but this WalletProtobufSerializer does not know how to persist this.");
}
}
if (wallet.getKeyRotationTime() != null) {
long timeSecs = wallet.getKeyRotationTime().getTime() / 1000;
walletBuilder.setKeyRotationTime(timeSecs);
}
populateExtensions(wallet, walletBuilder);
for (Map.Entry<String, ByteString> entry : wallet.getTags().entrySet()) {
Protos.Tag.Builder tag = Protos.Tag.newBuilder().setTag(entry.getKey()).setData(entry.getValue());
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());
return walletBuilder.build();
}
示例10: completeTxPartiallySignedMarriedThrows
import org.bitcoinj.signers.TransactionSigner; //导入依赖的package包/类
@Test (expected = TransactionSigner.MissingSignatureException.class)
public void completeTxPartiallySignedMarriedThrows() throws Exception {
byte[] emptySig = {};
completeTxPartiallySignedMarried(Wallet.MissingSigsMode.THROW, emptySig);
}
示例11: signTransaction
import org.bitcoinj.signers.TransactionSigner; //导入依赖的package包/类
/**
* <p>Given a send request containing transaction, attempts to sign it's inputs. This method expects transaction
* to have all necessary inputs connected or they will be ignored.</p>
* <p>Actual signing is done by pluggable {@link org.bitcoinj.signers.LocalTransactionSigner}
* and it's not guaranteed that transaction will be complete in the end.</p>
*/
void signTransaction(BitSendRequest req) {
lock.lock();
try {
Transaction tx = req.tx.getRawTransaction();
List<TransactionInput> inputs = tx.getInputs();
List<TransactionOutput> outputs = tx.getOutputs();
Preconditions.checkState(inputs.size() > 0);
Preconditions.checkState(outputs.size() > 0);
KeyBag maybeDecryptingKeyBag = new DecryptingKeyBag(account, req.aesKey);
int numInputs = tx.getInputs().size();
for (int i = 0; i < numInputs; i++) {
TransactionInput txIn = tx.getInput(i);
if (txIn.getConnectedOutput() == null) {
log.warn("Missing connected output, assuming input {} is already signed.", i);
continue;
}
try {
// We assume if its already signed, its hopefully got a SIGHASH type that will not invalidate when
// we sign missing pieces (to check this would require either assuming any signatures are signing
// standard output types or a way to get processed signatures out of script execution)
txIn.getScriptSig().correctlySpends(tx, i, txIn.getConnectedOutput().getScriptPubKey());
log.warn("Input {} already correctly spends output, assuming SIGHASH type used will be safe and skipping signing.", i);
continue;
} catch (ScriptException e) {
// Expected.
}
Script scriptPubKey = txIn.getConnectedOutput().getScriptPubKey();
RedeemData redeemData = txIn.getConnectedRedeemData(maybeDecryptingKeyBag);
Preconditions.checkNotNull(redeemData, "Transaction exists in wallet that we cannot redeem: %s", txIn.getOutpoint().getHash());
txIn.setScriptSig(scriptPubKey.createEmptyInputScript(redeemData.keys.get(0), redeemData.redeemScript));
}
TransactionSigner.ProposedTransaction proposal = new TransactionSigner.ProposedTransaction(tx);
TransactionSigner signer = new LocalTransactionSigner();
if (!signer.signInputs(proposal, maybeDecryptingKeyBag)) {
log.info("{} returned false for the tx", signer.getClass().getName());
}
// resolve missing sigs if any
new MissingSigResolutionSigner(req.missingSigsMode).signInputs(proposal, maybeDecryptingKeyBag);
} finally {
lock.unlock();
}
}
示例12: signTransaction
import org.bitcoinj.signers.TransactionSigner; //导入依赖的package包/类
/**
* <p>Given a send request containing transaction, attempts to sign it's inputs. This method expects transaction
* to have all necessary inputs connected or they will be ignored.</p>
* <p>Actual signing is done by pluggable {@link #signers} and it's not guaranteed that
* transaction will be complete in the end.</p>
*/
public void signTransaction(SendRequest req) {
lock.lock();
try {
Transaction tx = req.tx;
List<TransactionInput> inputs = tx.getInputs();
List<TransactionOutput> outputs = tx.getOutputs();
checkState(inputs.size() > 0);
checkState(outputs.size() > 0);
KeyBag maybeDecryptingKeyBag = new DecryptingKeyBag(this, req.aesKey);
int numInputs = tx.getInputs().size();
for (int i = 0; i < numInputs; i++) {
TransactionInput txIn = tx.getInput(i);
if (txIn.getConnectedOutput() == null) {
// Missing connected output, assuming already signed.
continue;
}
try {
// We assume if its already signed, its hopefully got a SIGHASH type that will not invalidate when
// we sign missing pieces (to check this would require either assuming any signatures are signing
// standard output types or a way to get processed signatures out of script execution)
txIn.getScriptSig().correctlySpends(tx, i, txIn.getConnectedOutput().getScriptPubKey());
log.warn("Input {} already correctly spends output, assuming SIGHASH type used will be safe and skipping signing.", i);
continue;
} catch (ScriptException e) {
// Expected.
}
Script scriptPubKey = txIn.getConnectedOutput().getScriptPubKey();
RedeemData redeemData = txIn.getConnectedRedeemData(maybeDecryptingKeyBag);
checkNotNull(redeemData, "Transaction exists in wallet that we cannot redeem: %s", txIn.getOutpoint().getHash());
txIn.setScriptSig(scriptPubKey.createEmptyInputScript(redeemData.keys.get(0), redeemData.redeemScript));
}
TransactionSigner.ProposedTransaction proposal = new TransactionSigner.ProposedTransaction(tx);
for (TransactionSigner signer : signers) {
if (!signer.signInputs(proposal, maybeDecryptingKeyBag))
log.info("{} returned false for the tx", signer.getClass().getName());
}
// resolve missing sigs if any
new MissingSigResolutionSigner(req.missingSigsMode).signInputs(proposal, maybeDecryptingKeyBag);
} finally {
lock.unlock();
}
}
示例13: completeTxPartiallySignedMarriedThrows
import org.bitcoinj.signers.TransactionSigner; //导入依赖的package包/类
@Test (expected = TransactionSigner.MissingSignatureException.class)
public void completeTxPartiallySignedMarriedThrows() throws Exception {
byte[] emptySig = new byte[]{};
completeTxPartiallySignedMarried(Wallet.MissingSigsMode.THROW, emptySig);
}
示例14: signTransaction
import org.bitcoinj.signers.TransactionSigner; //导入依赖的package包/类
/**
* <p>Given a send request containing transaction, attempts to sign it's inputs. This method expects transaction
* to have all necessary inputs connected or they will be ignored.</p>
* <p>Actual signing is done by pluggable {@link #signers} and it's not guaranteed that
* transaction will be complete in the end.</p>
*/
public void signTransaction(SendRequest req) {
lock.lock();
try {
Transaction tx = req.tx;
List<TransactionInput> inputs = tx.getInputs();
List<TransactionOutput> outputs = tx.getOutputs();
checkState(inputs.size() > 0);
checkState(outputs.size() > 0);
KeyBag maybeDecryptingKeyBag = new DecryptingKeyBag(this, req.aesKey);
int numInputs = tx.getInputs().size();
for (int i = 0; i < numInputs; i++) {
TransactionInput txIn = tx.getInput(i);
if (txIn.getConnectedOutput() == null) {
log.warn("Missing connected output, assuming input {} is already signed.", i);
continue;
}
try {
// We assume if its already signed, its hopefully got a SIGHASH type that will not invalidate when
// we sign missing pieces (to check this would require either assuming any signatures are signing
// standard output types or a way to get processed signatures out of script execution)
txIn.getScriptSig().correctlySpends(tx, i, txIn.getConnectedOutput().getScriptPubKey());
log.warn("Input {} already correctly spends output, assuming SIGHASH type used will be safe and skipping signing.", i);
continue;
} catch (ScriptException e) {
// Expected.
}
Script scriptPubKey = txIn.getConnectedOutput().getScriptPubKey();
RedeemData redeemData = txIn.getConnectedRedeemData(maybeDecryptingKeyBag);
checkNotNull(redeemData, "Transaction exists in wallet that we cannot redeem: %s", txIn.getOutpoint().getHash());
txIn.setScriptSig(scriptPubKey.createEmptyInputScript(redeemData.keys.get(0), redeemData.redeemScript));
}
TransactionSigner.ProposedTransaction proposal = new TransactionSigner.ProposedTransaction(tx);
for (TransactionSigner signer : signers) {
if (!signer.signInputs(proposal, maybeDecryptingKeyBag))
log.info("{} returned false for the tx", signer.getClass().getName());
}
// resolve missing sigs if any
new MissingSigResolutionSigner(req.missingSigsMode).signInputs(proposal, maybeDecryptingKeyBag);
} finally {
lock.unlock();
}
}
示例15: walletToProto
import org.bitcoinj.signers.TransactionSigner; //导入依赖的package包/类
/**
* Converts the given wallet to the object representation of the protocol buffers. This can be modified, or
* additional data fields set, before serialization takes place.
*/
public Protos.Wallet walletToProto(Wallet wallet) {
Protos.Wallet.Builder walletBuilder = Protos.Wallet.newBuilder();
walletBuilder.setNetworkIdentifier(wallet.getNetworkParameters().getId());
if (wallet.getDescription() != null) {
walletBuilder.setDescription(wallet.getDescription());
}
for (WalletTransaction wtx : wallet.getWalletTransactions()) {
Protos.Transaction txProto = makeTxProto(wtx);
walletBuilder.addTransaction(txProto);
}
walletBuilder.addAllKey(wallet.serializeKeychainToProtobuf());
for (Script script : wallet.getWatchedScripts()) {
Protos.Script protoScript =
Protos.Script.newBuilder()
.setProgram(ByteString.copyFrom(script.getProgram()))
.setCreationTimestamp(script.getCreationTimeSeconds() * 1000)
.build();
walletBuilder.addWatchedScript(protoScript);
}
// Populate the lastSeenBlockHash field.
Sha256Hash lastSeenBlockHash = wallet.getLastBlockSeenHash();
if (lastSeenBlockHash != null) {
walletBuilder.setLastSeenBlockHash(hashToByteString(lastSeenBlockHash));
walletBuilder.setLastSeenBlockHeight(wallet.getLastBlockSeenHeight());
}
if (wallet.getLastBlockSeenTimeSecs() > 0)
walletBuilder.setLastSeenBlockTimeSecs(wallet.getLastBlockSeenTimeSecs());
// Populate the scrypt parameters.
KeyCrypter keyCrypter = wallet.getKeyCrypter();
if (keyCrypter == null) {
// The wallet is unencrypted.
walletBuilder.setEncryptionType(EncryptionType.UNENCRYPTED);
} else {
// The wallet is encrypted.
walletBuilder.setEncryptionType(keyCrypter.getUnderstoodEncryptionType());
if (keyCrypter instanceof KeyCrypterScrypt) {
KeyCrypterScrypt keyCrypterScrypt = (KeyCrypterScrypt) keyCrypter;
walletBuilder.setEncryptionParameters(keyCrypterScrypt.getScryptParameters());
} else {
// Some other form of encryption has been specified that we do not know how to persist.
throw new RuntimeException("The wallet has encryption of type '" + keyCrypter.getUnderstoodEncryptionType() + "' but this WalletProtobufSerializer does not know how to persist this.");
}
}
if (wallet.getKeyRotationTime() != null) {
long timeSecs = wallet.getKeyRotationTime().getTime() / 1000;
walletBuilder.setKeyRotationTime(timeSecs);
}
populateExtensions(wallet, walletBuilder);
for (Map.Entry<String, ByteString> entry : wallet.getTags().entrySet()) {
Protos.Tag.Builder tag = Protos.Tag.newBuilder().setTag(entry.getKey()).setData(entry.getValue());
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());
return walletBuilder.build();
}