In this code i receive an already signed transaction in the form of a byte 
array and i would like to broadcast it to the Bitcoin network.

override fun onHandleIntent(intent: Intent?) {
    org.bitcoinj.core.Context.propagate(Constants.CONTEXT)
    if (intent != null) {
        when (intent.action) {
            ACTION_BROADCAST_TRANSACTION -> {
                initializeBlockchain(null, 0)
                val transactionByteArray = intent.getByteArrayExtra("TX")
                val tx = Transaction(Constants.NETWORK_PARAMETERS, 
transactionByteArray)
                tx.getConfidence().setSource(TransactionConfidence.Source.SELF);
                tx.setPurpose(Transaction.Purpose.USER_PAYMENT);
                SpvModuleApplication.getWallet()!!.maybeCommitTx(tx)
                if (peerGroup != null) {
                    val transactionBroadcast: TransactionBroadcast = 
peerGroup!!.broadcastTransaction(tx)
                    val future : ListenableFuture<Transaction> = 
transactionBroadcast.future()
                   
                    future.get() 
  ..........


Issue is that in my own code i already propagated the context but then 
internally in BitcoinJ it creates another thread when it has enough peers, 
and then broadcast the transaction from this thread, which fails as the 
Context is not propagated there.

Any pointers as to what i am doing wrong ?

Thanks.


09-14 15:14:52.867 8281-8330/com.m.s.test E/ExecutionList: RuntimeException 
>>> while executing runnable 
>>> org.bitcoinj.core.TransactionBroadcast$EnoughAvailablePeers@838ec24 with 
>>> executor org.bitcoinj.utils.Threading$2@7b38d
>>> java.lang.IllegalStateException: missing context
>>
>>  
>
>> at org.bitcoinj.core.Context.get(Context.java:110)
>>
>>  
>
>>
>>> at org.bitcoinj.core.Transaction.getConfidence(Transaction.java:1198)
>>
>>  
>
>>
>>> at 
>>> org.bitcoinj.core.TransactionBroadcast$EnoughAvailablePeers.run(TransactionBroadcast.java:134)
>>
>>  
>
>>
>>> at org.bitcoinj.utils.Threading$2.execute(Threading.java:141)
>>
>>  
>
>>
>>> at 
>>> com.google.common.util.concurrent.ExecutionList.executeListener(ExecutionList.java:156)
>>
>>  
>
>>
>>> at 
>>> com.google.common.util.concurrent.ExecutionList.execute(ExecutionList.java:145)
>>
>>  
>
>>
>>> at 
>>> com.google.common.util.concurrent.AbstractFuture.set(AbstractFuture.java:185)
>>
>>  
>
>>
>>> at 
>>> com.google.common.util.concurrent.SettableFuture.set(SettableFuture.java:53)
>>
>>  
>
>>
>>> at org.bitcoinj.core.PeerGroup$14.onPeerConnected(PeerGroup.java:1938)
>>
>>  
>
>>
>>> at org.bitcoinj.core.PeerGroup$11.run(PeerGroup.java:1565)
>>
>>  
>
>>
>>> at org.bitcoinj.utils.Threading$UserThread.run(Threading.java:107)
>>
>>

-- 
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 bitcoinj+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to