2) for example , if i have 2 bitcoin in my wallet, and the user withdraws one bitcoin, the rest coin (one bitcoin - fee) how calculated (utxo) ?
if its value isn't enough, Bitcoin core will have to include your other inputs or select the one with the right value,
otherwise, it will return with an error: "Insufficient funds"
The tricky part is to set the correct amount up to the last satoshi, if it was set with lower amount, a change output will be added.
For example (RegTest):
sendmany "" "{\"bcrt1qk3hqnujdex64v045qdh7df28vywg5rwtdzj008\":1,\"2Mu9fzGjgnuvCrAJ1cuAu1vZGfDVzHZNHKU\":18.10239312}" 1 "comment" "[\"2Mu9fzGjgnuvCrAJ1cuAu1vZGfDVzHZNHKU\"]"
- bcrt1qk3hqnujdex64v045qdh7df28vywg5rwtdzj008 - user's address that you'll pay.
- 2Mu9fzGjgnuvCrAJ1cuAu1vZGfDVzHZNHKU - your "new address" from other wallet that will receive the rest of the balance.
The example wallet's balance is 19.10239312 RegTestBTC, so the values of the outputs are 1 and 18.10239312 respectively.
But the final sent amount to 2Mu9fzGjgnuvCrAJ1cuAu1vZGfDVzHZNHKU is only 18.10238080 RegTestBTC because it's set with subtractfeefromamount flag "true".