Bitcoin Forum

Alternate cryptocurrencies => Altcoin Discussion => Topic started by: pineapples on November 02, 2015, 09:02:25 AM



Title: return change to send address for coind
Post by: pineapples on November 02, 2015, 09:02:25 AM

i would like to return change to the source input address in a coind.
the point being easy tracking of coins, and easy backing up.
it's for a faucet style use.

i assume the simplest thing is to change the src code, as i cannot find any other method other than creating raw tx every time.

can anyone help with the appropriate changes ??


Code:
                    // no coin control: send change to newly generated address
                    else
                    {
                        // Note: We use a new key here to keep it from being obvious which side is the change.
                        //  The drawback is that by not reusing a previous key, the change may be lost if a
                        //  backup is restored, if the backup doesn't have the new private key for the change.
                        //  If we reused the old key, it would be possible to add code to look for and
                        //  rediscover unknown transactions that were written with keys of ours to recover
                        //  post-backup change.

                        // Reserve a new key pair from key pool
                        CPubKey vchPubKey = reservekey.GetReservedKey();

                        scriptChange.SetDestination(vchPubKey.GetID());
                    }




Title: Re: return change to send address for coind
Post by: pineapples on November 04, 2015, 01:16:37 AM
here's early code from bitcoin core where it doesnt choose a random address for change.

i am unsure how the code syntax has changed since 2009 :D but i imagine it's changed a bit..

https://github.com/bitcoin/bitcoin/blob/8dca7864f793072701f810e4c5ea12a6e1087085/main.cpp#L2575

Code:
                if (nValueIn > nValue)
                {
                    /// todo: for privacy, should randomize the order of outputs,
                    //        would also have to use a new key for the change.
                    // Use the same key as one of the coins
                    vector<unsigned char> vchPubKey;
                    CTransaction& txFirst = *(*setCoins.begin());
                    foreach(const CTxOut& txout, txFirst.vout)
                        if (txout.IsMine())
                            if (ExtractPubKey(txout.scriptPubKey, true, vchPubKey))
                                break;
                    if (vchPubKey.empty())
                        return false;


                    // Fill vout[1] to ourself
                    CScript scriptPubKey;
                    scriptPubKey << vchPubKey << OP_CHECKSIG;
                    wtxNew.vout.push_back(CTxOut(nValueIn - nValue, scriptPubKey));
                }


Title: Re: return change to send address for coind
Post by: achow101 on November 04, 2015, 02:44:19 AM
How are you sending transactions? What is the command you are using?

Given that there is the option for a custom change address in the gui, you would think that there is an rpc command that lets you set the custom change, but I can't seem to find that.


Title: Re: return change to send address for coind
Post by: pineapples on November 04, 2015, 01:38:25 PM

i'm' just using a plain old

coind sendtoaddress xxxxxxxxxxxxxxxxxxxx 152.3


i havent come across a rpc command at all.
it shouldnt' be that hard to get the change address from one of the inputs, it just is too hard for me :)


Title: Re: return change to send address for coind
Post by: achow101 on November 04, 2015, 08:21:29 PM
I think you should be able to use the send many command: https://bitcoin.org/en/developer-reference#sendmany and have one of the outputs be to the change address. You would need to calculate the fee manually.


Title: Re: return change to send address for coind
Post by: Mercado on November 04, 2015, 10:25:03 PM
Or you can manually set the changeaddress when using a createrawtransaction https://en.bitcoin.it/wiki/Raw_Transactions


Title: Re: return change to send address for coind
Post by: pineapples on November 05, 2015, 02:19:35 PM

sendmany and rawtransactions both take a bit of pissing around.

thanks for your suggestions,
but changin the code to send it straight back to an input address should be much simpler.  it wont require any extra analysis of the inputs at all, nor any fee calculation.



Title: Re: return change to send address for coind
Post by: pineapples on April 15, 2016, 12:19:59 PM

:)
i'm still interested in finding a solution to this



Title: Re: return change to send address for coind
Post by: pineapples on April 15, 2016, 12:43:31 PM
lol. another attempt at google and actually find an answer !!

Diamond Coin has exactly it :D

https://github.com/DMDcoin/Diamond/commit/22f7eb608906d064cef043b45a2b5b17eb23f170#diff-d7618bdc04db23aa74d6a5a4198c58fd