novitski / bitcoinj

Automatically exported from code.google.com/p/bitcoinj
Apache License 2.0
0 stars 0 forks source link

invoice id attach problem #403

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello , we are writing ecommerce software.
But there is some problems we have.

We can hook on payment like this:

    @Override
    public void onCoinsReceived(Wallet w, Transaction tx, BigInteger prevBalance, BigInteger newBalance) {
        // MUST BE THREAD SAFE
        if (newBalance.equals(BigInteger.ZERO))
            return;
        if (!tx.isPending()) return;
        // It was broadcast, but we can't really verify it's valid until it appears in a block.
        BigInteger value = tx.getValueSentToMe(w);
        System.out.println("Received pending tx for " + Utils.bitcoinValueToFriendlyString(value) +
                ": " + tx);
        tx.getConfidence().addEventListener(new TransactionConfidence.Listener() {
            public void onConfidenceChanged(final Transaction tx2) {
                // MUST BE THREAD SAFE.

                if (tx2.getConfidence().getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING) {
                    // Coins were confirmed (appeared in a block).
                    tx2.getConfidence().removeEventListener(this);
                    // Run the process of sending the coins back on a separate thread. This is a temp hack
                    // until the threading changes in 0.9 are completed ... TX confidence listeners run
                    // with the wallet lock held and re-entering the wallet isn't always safe. We can solve
                    // this by just interacting with the wallet from a separate thread, which will wait until
                    // this thread is finished. It's a dumb API requirement and will go away soon.
                    threadQueue.execute(new Runnable() {
                        @Override
                        public final void run() {
                            //To change body of implemented methods use File | Settings | File Templates.
                            final BigInteger value = tx2.getValueSentToMe(wallet);
                            final TransactionInput input = tx2.getInputs().get(0);
                            try {
                                final Address from = input.getFromAddress();
                                remote.onBitcoinReceived( from.toString() , tx2.getHashAsString() );

                            } catch (ScriptException e) {
                                //e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                            }
                        }
                    });
                } else {
                    System.out.println(String.format("Confidence of %s changed, is now: %s",
                            tx2.getHashAsString(), tx2.getConfidence().toString()));
                }
            }
        });
//        // Now send the coins back!
//        Wallet.SendResult sendResult = w.sendCoins(peerGroup, from, value);
//        checkNotNull(sendResult);  // We should never try to send more coins 
than we have!
//        System.out.println("Sent coins back! Transaction hash is " + 
sendResult.tx.getHashAsString());
    }

But this time our problem is , we can get who is sending money.
by getting their bitcoin address.

But how can we get they pay that money for what?

There is no message we can get attachment.
So which invoice he pays for?

i heard we need to generate new address for each invoice.
So we can get what user pay money for from each address.
Binding addresses to each invoice is the solution.
But there is no sample how to do it ?

There is only sample how to hook :
    public void onCoinsReceived(Wallet w, Transaction tx, BigInteger prevBalance, BigInteger newBalance);

okay.
So how can i generate new address and how can i get received Address ?
or is there any better solution to this problem.

Original issue reported on code.google.com by kadir.ba...@gmail.com on 1 May 2013 at 4:56

GoogleCodeExporter commented 9 years ago
Copying Jims comment to the bug tracker:

When your customer places an order you can create a new Bitcoin address
just for that customer and specific order.  Put that Bitcoin address in
whatever database you are using for order tracking. When that address
receives bitcoin you can cross match to the order and you know who paid
and for what.

There should be examples for address creation in, say, WalletTool.

Original comment by hearn@google.com on 2 May 2013 at 9:44

GoogleCodeExporter commented 9 years ago
so , how can i create address and add coin receive listener ?
When user receives coins what can i do ?

Original comment by kadir.ba...@gmail.com on 2 May 2013 at 3:31

GoogleCodeExporter commented 9 years ago
Please review the documentation on these topics:

https://code.google.com/p/bitcoinj/wiki/GettingStarted
https://code.google.com/p/bitcoinj/wiki/WorkingWithTheWallet

Original comment by hearn@google.com on 2 May 2013 at 3:45

GoogleCodeExporter commented 9 years ago

Original comment by hearn@google.com on 11 Jul 2013 at 3:39