Bitcoin Forum
April 19, 2024, 09:52:36 PM *
News: Latest Bitcoin Core release: 26.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Size of raw transaction?  (Read 1953 times)
cheako911 (OP)
Member
**
Offline Offline

Activity: 70
Merit: 10


View Profile
February 21, 2015, 04:47:49 PM
 #1

Hello,
  I'm working with the raw transaction JSON interface, my question is about the application(subtract) of fee to a change address.  At the time of having a list of outputs, a selection of new outputs one being flexible(change address) in value, a total value of all inputs, and the value of the non-change outputs.  How can the size of the transaction be calculated?

One thought I had was to issue this to createrawtransaction with a bogus(1Satoshi?) value for change and compute the size from the returned hex, device by 2.  Though I was hoping for a simpler method, say each input is X bytes and each output is Y add these together with the constant header size of Q.

For my project it's *imperative to use specific outputs when sending coins.

* You may whine, bitch, complain, argue, stomp, stamp and even tantrum that this is some how wrong/bad/undesirable/ect...  Though it won't change project design goals and the problem would still remain.
1713563556
Hero Member
*
Offline Offline

Posts: 1713563556

View Profile Personal Message (Offline)

Ignore
1713563556
Reply with quote  #2

1713563556
Report to moderator
1713563556
Hero Member
*
Offline Offline

Posts: 1713563556

View Profile Personal Message (Offline)

Ignore
1713563556
Reply with quote  #2

1713563556
Report to moderator
Every time a block is mined, a certain amount of BTC (called the subsidy) is created out of thin air and given to the miner. The subsidy halves every four years and will reach 0 in about 130 years.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
DannyHamilton
Legendary
*
Offline Offline

Activity: 3360
Merit: 4570



View Profile
February 21, 2015, 05:37:21 PM
 #2

For my project it's *imperative to use specific outputs when sending coins.

* You may whine, bitch, complain, argue, stomp, stamp and even tantrum that this is some how wrong/bad/undesirable/ect...  Though it won't change project design goals and the problem would still remain.

I'll assume you are talking about the Bitcoin Core wallet?

All transactions have "specific outputs" when sending the transaction.  A transaction wouldn't make sense if it didn't.  Most people just let the wallet handle the transaction fee and change output for them, but if you prefer to have individual control over that, you can do so either with the coin control features (which can be turned on in the "Wallet" section of the "Preferences" menu), or with the createrawtransaction API call.  I wouldn't expect anybody to "whine, bitch, complain, argue, stomp, stamp and even tantrum that this is some how wrong/bad/undesirable/etc".

I'm working with the raw transaction JSON interface, my question is about the application(subtract) of fee to a change address.  At the time of having a list of outputs, a selection of new outputs one being flexible(change address) in value, a total value of all inputs, and the value of the non-change outputs.  How can the size of the transaction be calculated?

The size of the transaction can't be computed until after you've already sent it if you're using the "sendtoaddress", "sendfrom", or the "sendmany" API calls.

If you use the "createrawtransaction" then you will need to know more than the "total value of all inputs", you will need to know exactly which unspent outputs you are going to use as inputs.  Once you know that, you'll need to know if the inputs were received at compressed key addresses, or at uncompressed key addresses.  Using all of the above information, you can calculate the maximum likely transaction size as follows:

  • 10 bytes of required data for every transaction
  • 34 bytes for each output (including all change outputs)
  • Between 179 and 181 bytes inclusive for each input that was received at an uncompressed key address (exact size can't be computed until after the transaction is signed)
  • Between 147 and 149 bytes inclusive for each input that was received at an uncompressed key address (exact size can't be computed until after the transaction is signed)

One thought I had was to issue this to createrawtransaction with a bogus(1Satoshi?) value for change and compute the size from the returned hex, device by 2.

It's not enough to jsut "createrawtransaction".  You won't know the exact size until you "signrawtransaction".  If you then modify the change output, the size (in bytes) of the transaction might become different by up to 2X the number of inputs when you re-sign the transaction.  As such, depending on your particular use case, it might be easiest to just always assume that the inputs will contribute their largest size (149 bytes for compressed key and 181 bytes for uncompressed key).

Though I was hoping for a simpler method, say each input is X bytes and each output is Y add these together with the constant header size of Q.

Unfortunately, each input must be signed, and the size of the signature isn't known until after you've actually calculated the signature.  The signature consists of two 32 byte values, but if the first byte of either of those values is greater than or equal to 0x80 then an additional 0x00 byte is prepended to the value.
gmaxwell
Moderator
Legendary
*
expert
Offline Offline

Activity: 4158
Merit: 8382



View Profile WWW
February 21, 2015, 11:24:49 PM
Last edit: February 21, 2015, 11:38:10 PM by gmaxwell
 #3

For my project it's *imperative to use specific outputs when sending coins.
Well, you've given no information there. I'm afraid you may be mistaking the human participants on the forum for a search engine or mechanical turk. We don't generally answer questions in a vacuum.

Quote
* You may whine, bitch, complain, argue, stomp, stamp and even tantrum that this is some how wrong/bad/undesirable/ect...  Though it won't change project design goals and the problem would still remain.
You can insult people on the forum and provide inadequate information but that isn't likely to get your questions answers. Congrats on the self-defeat there.

You can set all the design goals you want, but no matter how many insults you hurl that isn't going to change the design of the Bitcoin system and so if it happens that what you're trying to accomplish turns out to be at odds with it, it's not going to work well, or will result in funds loss, etc.  It sounds like your understanding is currently pretty limited (e.g. not knowing how the size of a transaction works), you might want to attempt to understand the system a bit better before setting immutable design constraints and defending them with insults.  Just a thought.
najzenmajsen
Hero Member
*****
Offline Offline

Activity: 700
Merit: 500



View Profile
February 22, 2015, 12:28:13 AM
 #4

For my project it's *imperative to use specific outputs when sending coins.
Well, you've given no information there. I'm afraid you may be mistaking the human participants on the forum for a search engine or mechanical turk. We don't generally answer questions in a vacuum.
this made me laugh , quite alot honestly. I belive i just woke up the whole house man , but that's really not an issue because its apparently 7 AM. But i'd like to tell you before i go to sleep Maxwell that you've spread joy , to my heart and hopefully somebody else's what you typed was both romantic and funny at the same time. I'd like to thank you on the behalf of my heart and other's because im sure there's other people out there that did the same thing that i did. but just dont have the courage to reach out to you and say it. I hope you appreciated my text , because my keyboard is so loud i woke up my neighbors as well now... oh well
Goodnite.
doof
Hero Member
*****
Offline Offline

Activity: 765
Merit: 503


View Profile WWW
February 23, 2015, 06:31:22 AM
 #5

Code:
if (bitcoin.like != true)
{
github.CreateFork('yourcrappycoin');
}
gmaxwell
Moderator
Legendary
*
expert
Offline Offline

Activity: 4158
Merit: 8382



View Profile WWW
February 23, 2015, 06:32:39 AM
 #6

Doof, impressive that you managed a response even less useful than mine.
cheako911 (OP)
Member
**
Offline Offline

Activity: 70
Merit: 10


View Profile
February 26, 2015, 08:38:45 PM
 #7

DannyHamilton++

Seriously you other fools, how hard is it to say...

Try your equations with:
Q=10
Y=34
X=147 to 181 mostly 147 to 149.

I hate ppl on the internet for assuming they need to know intimate details of my sex life in order to solve for X.  If I didn't say why I needed some of these variables filled in it's likely because it's private and none of you god dam business.
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!