So, after understanding how to create and send raw transactions on the basis of 'How to send from many bitcoin addresses to one bitcoin address?', in practice I still struggle with transaction fees. For example, I do the following in order to calculate the size of an hex-encoded transaction:
hex_raw_transaction = createrawtransaction(...)
hex_raw_transaction = signrawtransaction(hex_raw_transaction)
byte[] size = HexStringToByteArray(hex_raw_transaction)
int transaction_size = size.Length
Is that a correct way to determinate the transaction size? (Regarding to https://en.bitcoin.it/wiki/Transaction_fees)?
Is it correct that the transaction fee is set by the unassigned amount in the outputs?
For example, if I have 1 BTC in one address and send the 0.65 BTC to a second address and 0.3495 BTC as change to the first
//The fee will be:
fee = 1 - (0.65 + 0.3495) //= 0.0005 btc
is it correct that the fee will be 0.0005 BTC?