Thanks a lot for your reply, I just want to send transaction by peer to 
peer, follow your suggestion, I finished the transfer function, but the 
receive bitcoin address did not receive bitcoin, here is my source code, 
can you help me to find something wrong with my code?

public void transfer(List<SendIn> sendInList,
List<SendOut> sendOutList, List<String> privateKeys) {
NetworkParameters networkParameters = TestNet3Params.get();
Transaction myOwnConstructedTx = new Transaction(networkParameters);
// List<TransactionOutput> outputsToMyAddr = something(); // where ever you 
got these from
try {
for (int i = 0; i < sendInList.size(); i++) {
String address = sendInList.get(i).getAddress();
String txHash = sendInList.get(i).getTxHash();
String txData = getTxData(txHash);
byte[] bytes = Utils.HEX.decode(txData);
Transaction spentTx = new Transaction(networkParameters, bytes);
for (int j = 0; j < spentTx.getOutputs().size(); j++) {
if (address.equals(spentTx.getOutput(j).getScriptPubKey()
.getToAddress(networkParameters).toString())) {
myOwnConstructedTx.addInput(spentTx.getOutput(j));
break;
}
}
}

for (int i = 0; i < sendOutList.size(); i++) {
String addressJson = sendOutList.get(i).getAddress();
String coinJson = sendOutList.get(i).getValue().toString();
Address address = new Address(networkParameters, addressJson);
Coin coin = Coin.parseCoin(coinJson);
myOwnConstructedTx.addOutput(coin, address);
}
} catch (Exception e) {
e.printStackTrace();
}
// myOwnConstructedTx.addInput(outputsToMyAddr.get(0));

List<ECKey> eckeys = new ArrayList<ECKey>();
for (String privateKey : privateKeys) {
ECKey key;
            if (privateKey.length() == 51 || privateKey.length() == 52) {
                DumpedPrivateKey dumpedPrivateKey = 
DumpedPrivateKey.fromBase58(networkParameters, privateKey);
                key = dumpedPrivateKey.getKey();
            } else {
                BigInteger privKey = Base58.decodeToBigInteger(privateKey);
                key = ECKey.fromPrivate(privKey);
            }
            
            eckeys.add(key);
}
KeyChainGroup group = new KeyChainGroup(networkParameters);
group.importKeys(eckeys);
KeyBag keys =  new Wallet(networkParameters, group); // or a wallet, or 
something else with keys that can sign the used UTXO

TransactionInput input = myOwnConstructedTx.getInput(0);
Script scriptPubKey = 
myOwnConstructedTx.getInput(0).getConnectedOutput().getScriptPubKey();
RedeemData redeemData = input.getConnectedRedeemData(keys);
input.setScriptSig(scriptPubKey.createEmptyInputScript(redeemData.keys.get(0), 
redeemData.redeemScript));
TransactionSigner.ProposedTransaction proposal = new 
TransactionSigner.ProposedTransaction(myOwnConstructedTx);
new LocalTransactionSigner().signInputs(proposal, keys);

PeerGroup peerGroup = new PeerGroup(networkParameters);
peerGroup.broadcastTransaction(myOwnConstructedTx);
}




在 2016年12月14日星期三 UTC+8上午5:53:22,Tobias B.写道:
>
> What do you mean by not in your wallet? I think you need the UTXO in some 
> way. But it doesn't have to be contained in a wallet. When you have 
> information about a transaction that pays to your bitcoin address you can 
> construct a transaction using this UTXO without a wallet by construction 
> the transaction yourself.
> Let's say you have a list of transaction outputs that pay to your address 
> and are not already spent:
>
> List<TransactionOutput> outputsToMyAddr = something(); // where ever you 
> got these from
>
> Transaction myOwnConstructedTx = new 
> Transaction(myconf.getNetworkParameters());
>
> myOwnConstructedTx.addInput(outputsToMyAddr.get(0));
>
> KeyBag keys = getSomeKeyChainGroup(); // or a wallet, or something else 
> with keys that can sign the used UTXO
>
> TransactionInput input = myOwnConstructedTx.getInput(0);
> Script scriptPubKey = 
> myOwnConstructedTx.getInput(0).getConnectedOutput().getScriptPubKey();
> RedeemData redeemData = txIn.getConnectedRedeemData(keys);
> input.setScriptSig(scriptPubKey.createEmptyInputScript(redeemData.keys.get(0),
>  
> redeemData.redeemScript));
> TransactionSigner.ProposedTransaction proposal = new 
> TransactionSigner.ProposedTransaction(tx);
> new LocalTransactionSigner().signInputs(proposal, keys);
>
> PeerGroup peerGroup = getAPeerGroup();
> peerGroup.broadcastTransaction(tx);
>
> I think something like that should do it.
>
> Am Montag, 12. Dezember 2016 08:33:31 UTC+1 schrieb liuwh:
>>
>> is it possible send transaction from one bitcoin address (not in wallet) 
>> to another address by bitcoinj?
>> I have read some bitcoinj sample about send transaction in bitcoinj, 
>> almost all of them are realized by Wallet, UTXO's are  in wallet.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"bitcoinj" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to