Bitcoin Forum
November 19, 2024, 11:06:48 AM *
News: Check out the artwork 1Dq created to commemorate this forum's 15th anniversary
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Transaction, addresses and balance  (Read 697 times)
xrn (OP)
Sr. Member
****
Offline Offline

Activity: 332
Merit: 250



View Profile
May 16, 2016, 09:14:52 AM
Last edit: May 16, 2016, 09:57:56 AM by xrn
 #1

Hi

I need help / information what I am doing wrong. I setup my testnet wallet and client. I make web wallet in PHP. I have 3 different accounts: xrn1 , xrn2, xrn3.  And now I have two options:

1. Using all the time RPC command: getaddressesbyaccount and when I want to send BTC to my account for example: xrn1 I all the time have the same address (for my business this will be good solution). But I have problem, how I can in easy way display unspent balance on this account ? I send 1st transaction to my empty wallet and I have 12 BTC. Next I use it to make new trasaction where I send 2 BTC to my friend and 10 BTC to my wallet (the same address) and next I use command getbalance it shows me 22BTC - why ? I found command listaddressgroupings where amount is corrent but dont know I should use it.

2. Using all the time RPC command: getaccountaddress and when my address is not empty i generate new one and I have one transaction in one wallet but I dont know this is necessary and how it can help me (more secure ? someone cant inspect how many BTC i have ?). Next I have 12 BTC on my account and I send like before 2 BTC to my friend and 10 BTC to me but this time I will use new address. But if someone send me 3 new transaction like 1BTC, 5BTC, 10BTC, how can I  properly display available balance (12-12(i send it)+10+1+5+10 = 26BTC not 38BTC) ?

Edit:
Why if I run listtransactions without account name I had this output:

"account": "",
"address": "myszF9nUaBURai2joeSECwoGGKCzQRJLZZ",
"category": "send",
"amount": -10.49990000,

why my account field is empty ? when I run listtransaction with account name I have only incoming payments but 0 output transactions.

Btw. Command listunspent return me corrent value.
DannyHamilton
Legendary
*
Offline Offline

Activity: 3486
Merit: 4851



View Profile
May 16, 2016, 03:29:54 PM
 #2

An "account" in bitcoin core is like a bank account.  When you deposit cash at the bank, they don't set aside those specific currency notes just for you.  They all get mixed together in the vault.  When you withdraw cash, you most likely will get cash that someone else deposited.

Bitcoins that are received at an account are not locked to that account in any way, and bitcoins that are sent from an account may have been received at a different account.  It is even possible for an account in Bitcoin Core to have a negative value if you have enough bitcoins in some other account to cover the difference.  Additionally, Bitcoin Core maintains a default unnamed account for transactions that occur without an account specified.

xrn (OP)
Sr. Member
****
Offline Offline

Activity: 332
Merit: 250



View Profile
May 16, 2016, 05:39:15 PM
 #3

Ok I think I understound. All works great when I use sendfrom "account" or sendtoaddress. This funcions are safe to use it ? What is different between commands createrawtransaction txid, signrawtransaction and sendrawtransaction and sendtoaddress ?
jonnybravo0311
Legendary
*
Offline Offline

Activity: 1344
Merit: 1024


Mine at Jonny's Pool


View Profile WWW
May 16, 2016, 05:49:24 PM
 #4

Ok I think I understound. All works great when I use sendfrom "account" or sendtoaddress. This funcions are safe to use it ? What is different between commands createrawtransaction txid, signrawtransaction and sendrawtransaction and sendtoaddress ?
createrawtransaction requires you to manually enter the inputs and outputs.  You need to know the unspent transaction outputs you wish to use as your inputs.

signrawtransaction does exactly what it sounds like: sign the raw transaction you just created

sendrawtransaction: broadcasts the signed transaction you created

sendtoaddress: does all the stuff of createrawtransaction, signrawtransaction and sendrawtransaction.  It doesn't require you to know all of your UTXO.  All of that is managed behind the scenes.  It'll pick the inputs and create a change address for you.  All you have to input is the address to which you wish to send the coins, and how many coins you wish to send.

Jonny's Pool - Mine with us and help us grow!  Support a pool that supports Bitcoin, not a hardware manufacturer's pockets!  No SPV cheats.  No empty blocks.
DannyHamilton
Legendary
*
Offline Offline

Activity: 3486
Merit: 4851



View Profile
May 16, 2016, 09:59:36 PM
 #5

- snip -
sendfrom "account" or sendtoaddress. This funcions are safe to use it ?
- snip -

All the functions are "safe" as long as you know what you are doing and you use them properly.

Most functions are not "safe" if you don't know what you are doing and you use them incorrectly.

"sendfrom account"  Will create a transaction and will update the account balance for that account.  You can not count on it only using transaction outputs that were received associated with that account.

"sendtoaddress" will create a transaction and (if I recall correctly) will update the default account on the wallet. (I might be mistaken on that. It might not update any account at all. I'm not confident in my answer and you may want to wait for additional responses from someone more knowledgable than me on the "sendtoaddress" function).

Generally, I would advice that you create your own account system outside the wallet.  Use the wallet only for creating transactions, and for notifications about transactions and/or blocks. You have very limited control over the accounts in the wallet, and if you create your own account system, you'll be better positioned to handle activity in the way that you want it handled.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!