I am writing a simple application of POE through bitcoinj. Now I am testing
my app on the Testnet3.
I have produced some new Eckeys and built transactions to pour tiny coins
into them.
Just like in
https://live.blockcypher.com/btc-testnet/tx/60a11806a76ce4fb31fd9f93fc77ac70a3aecbfe4642d19cd104e70df36a7e67/
where the Output[2] looks
I recorded the priKeys of them but didn't want to add them to my wallet
(cos I don't want the connected UTXOs to be spent automatically by the
wallet coin selector)
The next step I want to build a new tx which one of its input spends the
Output[2](one of the UTXOs owned by the Eckeys) . However sth annoyed me
happens:
I build the tx like this:
Sha256Hash txhash =
Sha256Hash.wrap("60a11806a76ce4fb31fd9f93fc77ac70a3aecbfe4642d19cd104e70df36a7e67");
Transaction tx = bitcoin.wallet().getTransaction(txhash);
System.out.println(tx);
Transaction txTest = new Transaction(params);
ECKey myEckey =
ECKey.fromPrivate(Hex.decode("a95cb1b7a8af7c4f25a7cbf42c6a2da87e252b249674ee1d6b380d0bc10fa55f"));
System.out.println(myEckey);
String ss = "sdssddsdsdsd";
txTest.addOutput(Coin.ZERO,ScriptBuilder.createOpReturnScript(ss.getBytes()));
txTest.addOutput(Coin.valueOf(5000),myEckey.toAddress(params));
TransactionInput txInput = txTest.addSignedInput(tx.getOutput(2),myEckey,
Transaction.SigHash.ALL,false);
As the result of the input hasn't got enough coin. I need the wallet to
help to finish the tx by SendRequest.forTx:
So I do
SendRequest s = SendRequest.forTx(txTest);
Main.bitcoin.wallet().sendCoins(s);
The result is that the wallet supplies an input and a redeem output to the
tx.
However, as the operation add extra input and output. The SigScript of
input[0] doesn't work any more.
The wallet tried to resign the input[0] and cos it doesn't know its ECkey.
An Exception was caught:
java.lang.NullPointerException: Transaction exists in wallet that we cannot
redeem: 60a11806a76ce4fb31fd9f93fc77ac70a3aecbfe4642d19cd104e70df36a7e67
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:250)
at org.bitcoinj.wallet.Wallet.signTransaction(Wallet.java:4067)
at org.bitcoinj.wallet.Wallet.completeTx(Wallet.java:4003)
at org.bitcoinj.wallet.Wallet.sendCoinsOffline(Wallet.java:3767)
at org.bitcoinj.wallet.Wallet.sendCoins(Wallet.java:3834)
at org.bitcoinj.wallet.Wallet.sendCoins(Wallet.java:3864)
at wallettemplate.MainController.handleTestBtn(MainController.java:295)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
at
javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
at
com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at
com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at
com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at
com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at
com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at
com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at
com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at
com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at
com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at
com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8413)
at javafx.scene.control.Button.fire(Button.java:185)
at
com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at
com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at
com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at
com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at
com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at
com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at
com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at
com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at
com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at
com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at
com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at
com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at
com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at
com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at
com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:381)
at
com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at
com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:417)
at
com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at
com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at
com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
and the signing work had to stop. And txinput[1] hasn't got its ScriptSig
either.
After this ,I had tried to finish the signing work of txinput[0] manually
and let the wallet to finish the signing work of txinput[1].So I tried this:
catch (NullPointerException e){
//System.out.println("1:" + txTest);
txTest.getInput(0).clearScriptBytes();
Sha256Hash hash = txTest.hashForSignature(0,
txInput.getConnectedOutput().getScriptPubKey(), Transaction.SigHash.ALL, false);
ECKey.ECDSASignature ecSig = myEckey.sign(hash);
TransactionSignature txSig = new TransactionSignature(ecSig,
Transaction.SigHash.ALL, false);
txInput.setScriptSig(ScriptBuilder.createInputScript(txSig, myEckey));
SendRequest s = SendRequest.forTx(txTest);
try{
//s.signInputs = false;
Main.bitcoin.wallet().sendCoins(s);
System.out.println("2:" + txTest);
}catch (Exception ei){
ei.printStackTrace();
}
but it still doesn't work either,another
java.lang.NullPointerException: Transaction exists in wallet that we cannot
redeem: 60a11806a76ce4fb31fd9f93fc77ac70a3aecbfe4642d19cd104e70df36a7e67
was caught.
set sendRequest.signInputs=false didn't work also,cos the signing work of
txinput[1] hadn't finished yet.
Should I also finish the signing work of txinput[1] manually?? or do
anything else to avoid the exception??
Throughout the process ,I feel my way to resolve the problem was
unadvisable and troublesome.
Is there any simpler way to solve the problem like this?
Or some simple way to custom make the coin select rule?(I haven't do
surveys about this)
--
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.