Hi,
When i am trying to do Assurance contract, the transaction is not getting
added in blockchain and getting the below error. Please find the
transaction detail also as below.
Why the transaction is getting rejected and how to resolve the same. Please
find the attached source code which i am using.
*SEVERE: [2001:4800:7818:103:be76:4eff:fe05:f119]:18333 /Satoshi:0.12.1/:
Received Reject: tx
239d75a563a5aeda81ce6396683c32d74858db9c1d871e1b928c0c2e871ea544 for reason
'insufficient priority' (66)*
Paid {} satoshis in fees to create pledge tx {}
239d75a563a5aeda81ce6396683c32d74858db9c1d871e1b928c0c2e871ea544
updated: 2017-05-18T01:46:55Z
in
PUSHDATA(72)[3045022100fe582f3a3066295d14578506266aa99dbb7f08d0507a97a397026fc545b575fb02205bd9c84ad62e22f4c9fe6cf37389cf26ab7d1787341aeeec56ed77fe27bc560581]
PUSHDATA(33)[025c66f18877f0ab7ed7f3cc2523cfdf86f1761c3d865181636b305fffa65e67a0]
0.0025 BTC
outpoint:59d4a3cac34334c955a32266b5a215d3bb1e4155c90fef461e1e592303ecb8d1:1
hash160:54f50c0e5825a5463a579afdeeddd9dcb843274f
in
PUSHDATA(72)[304502210091404bc945fcb7023e7fd5132d944689fe79394ac080645219b6128d5ac00a5a0220374d09ebebfb306cceffc14026219bca4e482ad93d8135f6e457484bd1862bfe81]
PUSHDATA(33)[024de0481f28e6ac8fff47252481edb0f0abdf9404d251393c531e61294c32d8ac]
0.0015 BTC
outpoint:50bcea95914521dc4dcfdc210f45aee41dd35a17a21d58f9e54e245ad8d9a26d:0
hash160:ce0df459881561cf8c2bca7a97d8ed9810afe64d
in
PUSHDATA(72)[3045022100e17f6052cab558505a827c40e944ce4be3b1cbba594f13960a85c4f88a1cc1c80220633235e5f918df3fa3329548bbcea06afb9984fbe495ef8fe96a7da57cb2f66481]
PUSHDATA(33)[02b4ac87132155e7c053c6e001a5b8b5110799300745878465d772f2c510d0812b]
0.001 BTC
outpoint:4c3c3b6d1195a8b38c8d407dd76d27b5eb5fea7219c253b5df4a798718b1d7c4:0
hash160:25be6926978f89a7a7128855e2c3bc22dbc7e8ab
out DUP HASH160
PUSHDATA(20)[0a7d4079480869b03982e8652abd502fae64042f] EQUALVERIFY CHECKSIG
0.005 BTC
fee 0.00 BTC/kB, 0.00 BTC for 488 bytes
prps ASSURANCE_CONTRACT_CLAIM
Thanks,
Ramesh A
--
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.
package org.bitcoinj.tools;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.bitcoinj.core.Coin.valueOf;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.bitcoinj.core.Address;
import org.bitcoinj.core.BlockChain;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.InsufficientMoneyException;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.PeerGroup;
import org.bitcoinj.core.Sha256Hash;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.TransactionBroadcast;
import org.bitcoinj.core.Transaction.SigHash;
import org.bitcoinj.core.TransactionInput;
import org.bitcoinj.core.TransactionOutput;
import org.bitcoinj.core.VerificationException;
import org.bitcoinj.crypto.KeyCrypter;
import org.bitcoinj.crypto.KeyCrypterScrypt;
import org.bitcoinj.crypto.TransactionSignature;
import org.bitcoinj.kits.WalletAppKit;
import org.bitcoinj.params.TestNet3Params;
import org.bitcoinj.script.Script;
import org.bitcoinj.script.ScriptBuilder;
import org.bitcoinj.store.BlockStore;
import org.bitcoinj.store.BlockStoreException;
import org.bitcoinj.store.MemoryBlockStore;
import org.bitcoinj.utils.Threading;
import org.bitcoinj.wallet.SendRequest;
import org.bitcoinj.wallet.UnreadableWalletException;
import org.bitcoinj.wallet.Wallet;
import org.bitcoinj.wallet.Wallet.SendResult;
import org.bitcoinj.wallet.listeners.WalletCoinsReceivedEventListener;
import org.spongycastle.crypto.params.KeyParameter;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.AtomicDouble;
public class AssuranceContract22 {
private static KeyCrypter scrypter = new KeyCrypterScrypt();
private static KeyParameter aesKey = scrypter.deriveKey("we never went to the moon");
private static ECKey leadBankkey= null;
private static ECKey citiBankkey= null;
private static ECKey jpmcBankkey= null;
private static ECKey destkey= null;
private static Coin boaAmount = valueOf(250000);
private static Coin citiAmount = valueOf(150000);
private static Coin jpmcAmount = valueOf(100000);
private static Coin finalAmount = valueOf(500000);
private static Address leadBankAddr=null;
private static Address citiBankAddr=null;
private static Address jpmcBankAddr=null;
private static Address destBankAddr=null;
private static NetworkParameters params= TestNet3Params.get();
private static Address toAddr=null;
public static void main(String[] args) {
System.out.println(boaAmount);
System.out.println(citiAmount);
System.out.println(jpmcAmount);
System.out.println(finalAmount);
try {
File boaFile= new File("R:\\Projects\\BitCoin\\BOFA.wallet");
Wallet boaWallet = Wallet.loadFromFile(boaFile);
leadBankkey= boaWallet.currentReceiveKey();
leadBankAddr = leadBankkey.toAddress(params);
System.out.println(boaWallet.getBalance());
File citiFile= new File("R:\\Projects\\BitCoin\\CITI.wallet");
Wallet citiWallet = Wallet.loadFromFile(citiFile);
citiBankkey= citiWallet.currentReceiveKey();
citiBankAddr = citiBankkey.toAddress(params);
System.out.println(citiWallet.getBalance());
File jpmcFile= new File("R:\\Projects\\BitCoin\\JPMC.wallet");
Wallet jpmcWallet = Wallet.loadFromFile(jpmcFile);
jpmcBankkey= jpmcWallet.currentReceiveKey();
jpmcBankAddr = jpmcBankkey.toAddress(params);
System.out.println(jpmcWallet.getBalance());
//File destFile= new File("R:\\Projects\\BitCoin\\BOFA.wallet");
//Wallet destinationWallet = Wallet.loadFromFile(destFile);
destkey= boaWallet.currentReceiveKey();
destBankAddr = boaWallet.freshReceiveAddress();
System.out.println(boaWallet.getBalance());
Transaction depentxn1 = createDependency(boaWallet,boaFile,leadBankAddr,boaAmount);
Transaction depentxn2 = createDependency(citiWallet,citiFile,citiBankAddr,citiAmount);
Transaction depentxn3 = createDependency(jpmcWallet,jpmcFile,jpmcBankAddr,jpmcAmount);
System.out.println("depentxn1 " +depentxn1);
System.out.println("depentxn2 " +depentxn2);
System.out.println("depentxn3 " +depentxn3);
TransactionOutput depTxnOut1 = findOutputOfValue(boaAmount, depentxn1.getOutputs());
TransactionOutput depTxnOut2 = findOutputOfValue(citiAmount, depentxn2.getOutputs());
TransactionOutput depTxnOut3 = findOutputOfValue(jpmcAmount, depentxn3.getOutputs());
System.out.println("depTxnOut1 " +depTxnOut1);
System.out.println("depTxnOut2 " +depTxnOut2);
System.out.println("depTxnOut3 " +depTxnOut3);
Transaction pledgetxn1 = makePledge(boaWallet,boaFile,leadBankkey,depTxnOut1,null);
Transaction pledgetxn2 = makePledge(citiWallet,citiFile,citiBankkey,depTxnOut2,null);
Transaction pledgetxn3 = makePledge(jpmcWallet,jpmcFile,jpmcBankkey,depTxnOut3,null);
Transaction contract = new Transaction(params);
addPledges(pledgetxn1, contract);
addPledges(pledgetxn2, contract);
addPledges(pledgetxn3, contract);
contract.addOutput(finalAmount,destBankAddr);
contract.setPurpose(Transaction.Purpose.ASSURANCE_CONTRACT_CLAIM);
contract.verify();
SendRequest req = SendRequest.forTx(contract);
req.feePerKb = Coin.ZERO;
boaWallet.signTransaction(req);
boaWallet.commitTx(contract);
System.out.println(" Contract "+contract);
System.out.println("leadBankAddr"+leadBankAddr);
System.out.println("destBankAddr"+destBankAddr);
boaWallet.saveToFile(boaFile);
BlockStore blockStore = new MemoryBlockStore(params);
BlockChain chain;
chain = new BlockChain(params, boaWallet, blockStore);
final PeerGroup peerGroup = new PeerGroup(params, chain);
peerGroup.startAsync();
TransactionBroadcast ss= peerGroup.broadcastTransaction(contract);
System.out.println(" broadcasting pledge to the world "+ contract.getHashAsString());
System.out.println("Paid {} satoshis in fees to create pledge tx {}"+ contract);
final AtomicDouble p2 = new AtomicDouble();
ss.setProgressCallback(new TransactionBroadcast.ProgressCallback() {
@Override
public void onBroadcastProgress(double progress) {
System.out.println("progress "+progress);
p2.set(progress);
}
}, Threading.SAME_THREAD);
System.out.println("progress out");
boaWallet.saveToFile(boaFile);
peerGroup.downloadBlockChain();
peerGroup.stopAsync();
System.out.println("Execution ended");
boaWallet.saveToFile(boaFile);
} catch (UnreadableWalletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static Transaction createDependency(Wallet wallet,File walletFile, Address address,Coin pledgeAmount){
Transaction rootFinalTxn = new Transaction(params);
try {
SendRequest rootTxn = SendRequest.to(address, pledgeAmount);
/*rootTxn.shuffleOutputs = false;
rootTxn.aesKey = aesKey;*/
wallet.completeTx(rootTxn);
rootFinalTxn = rootTxn.tx;
wallet.commitTx(rootFinalTxn);
System.out.println("rootTxn "+rootFinalTxn);
wallet.saveToFile(walletFile);
} catch (InsufficientMoneyException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rootFinalTxn;
}
public static Transaction makePledge(Wallet wallet,File walletFile,ECKey key, TransactionOutput deptxn, Transaction tx) {
Transaction pledge = new Transaction(params);
try{
// TODO: Support submitting multiple inputs in a single pledge tx here.
TransactionInput input = pledge.addInput(deptxn);
pledge.addOutput(finalAmount, destBankAddr);
//ECKey key = input.getOutpoint().getConnectedKey(this);
checkNotNull(key);
Script script = deptxn.getScriptPubKey();
/* if (aesKey != null){
key = key.maybeDecrypt(aesKey);
System.out.println("entered into this");
}*/
TransactionSignature signature = pledge.calculateSignature(0, key, script,
Transaction.SigHash.ALL, true /* anyone can pay! */);
if (script.isSentToAddress()) {
input.setScriptSig(ScriptBuilder.createInputScript(signature, key));
System.out.println("entered into this=============>>");
} else if (script.isSentToRawPubKey()) {
// This branch will never be taken with the current design of the app because the only way to get money
// in is via an address, but in future we might support direct-to-key payments via the payment protocol.
input.setScriptSig(ScriptBuilder.createInputScript(signature));
}
input.setScriptSig(ScriptBuilder.createInputScript(signature, key));
pledge.setPurpose(Transaction.Purpose.ASSURANCE_CONTRACT_PLEDGE);
System.out.println("Paid {} satoshis in fees to create pledge tx {}"+ pledge);//totalFees
wallet.saveToFile(walletFile);
}catch(Exception ex){
System.out.println(ex);
}
return pledge;
}
public static Transaction addPledges(Transaction pledges, Transaction contract){
//pledges.getOutputs().forEach(contract::addOutput);
pledges.getInputs().forEach(contract::addInput);
return contract;
}
private static TransactionOutput findOutputOfValue(Coin value, Collection<TransactionOutput> outputs) {
for (TransactionOutput txSent : outputs){
Coin value2 = txSent.getValue();
System.out.println(value2);
}
return outputs.stream()
.filter(out -> out.getValue().equals(value))
.findFirst()
.orElse(null);
}
}