# 比特币原理——交易与UTXO

## UTXO

UTXO (Unspent Transaction Output) 未花费交易输出

1. 判断A的账户余额大于等于20元；
2. 在B的账户上加20元；
3. 同时在A的账户上减20元。

{
"n":1,
"script":"76a9142ae017a5bd24a3f935897085253e503fbfd66f4e88ac",
"spent":false,
"tx_index":335926477,
"type":0,
"value":21680000
}


## 交易

UTXO属于交易中的一部分，交易由输入和输出两部分组成。一笔交易的数据格式如下：

{
"txid":"5be7a9e47f56c98e5297a44df52da0475f448ece98bb51489103cdf70653092f",
"hash":"5be7a9e47f56c98e5297a44df52da0475f448ece98bb51489103cdf70653092f",
"version":1,
"size":224,
"vsize":224,
"locktime":0,
"vin": [...],
"vout": [...],
"hex":"0100000001a90b4101e6cbb75e1ff885b6358264627581e9f96db9ae609acec98d72422067000000006b483045022100c42c89eb2b10aeefe27caea63f562837b20290f0a095bda39bec37f2651af56b02204ee4260e81e31947d9297e7e9e027a231f5a7ae5e21015aabfdbdb9c6bbcc76e0121025e6e9ba5111117d49cfca477b9a0a5fba1dfcd18ef91724bc963f709c52128c4ffffffff02a037a0000000000017a91477df4f8c95e3d35a414d7946362460d3844c2c3187e6f6030b000000001976a914aba7915d5964406e8a02c3202f1f8a4a63e95c1388ac00000000",
"blockhash":"0000000000000000000c23ca00756364067ce5e815deb5982969df476bfc0b5c",
"confirmations":5,
"time":1521981077,
"blocktime":1521981077
}


sum(inputs.vlaue) = sum(outputs.value) + fee


### 输入

{
"vin":[
{
"txid":"672042728dc9ce9a60aeb96df9e9817562648235b685f81f5eb7cbe601410ba9",
"vout":0,
"scriptSig":{
"asm":"3045022100c42c89eb2b10aeefe27caea63f562837b20290f0a095bda39bec37f2651af56b02204ee4260e81e31947d9297e7e9e027a231f5a7ae5e21015aabfdbdb9c6bbcc76e[ALL] 025e6e9ba5111117d49cfca477b9a0a5fba1dfcd18ef91724bc963f709c52128c4",
"hex":"483045022100c42c89eb2b10aeefe27caea63f562837b20290f0a095bda39bec37f2651af56b02204ee4260e81e31947d9297e7e9e027a231f5a7ae5e21015aabfdbdb9c6bbcc76e0121025e6e9ba5111117d49cfca477b9a0a5fba1dfcd18ef91724bc963f709c52128c4"
},
"sequence":4294967295
}
]
}


### 输出

{
"vout":[
{
"value":0.10500000,
"n":0,
"scriptPubKey":{
"asm":"OP_HASH160 77df4f8c95e3d35a414d7946362460d3844c2c31 OP_EQUAL",
"hex":"a91477df4f8c95e3d35a414d7946362460d3844c2c3187",
"reqSigs":1,
"type":"scripthash",
"3CcqrGq4oQcfx3u75ijj4tDiqf4HJvhoeP"
]
}
},
{
"value":1.84809190,
"n":1,
"scriptPubKey":{
"asm":"OP_DUP OP_HASH160 aba7915d5964406e8a02c3202f1f8a4a63e95c13 OP_EQUALVERIFY OP_CHECKSIG",
"hex":"76a914aba7915d5964406e8a02c3202f1f8a4a63e95c1388ac",
"reqSigs":1,
"type":"pubkeyhash",
"1GedHcxdxq2tab98hqAmREUK9BBYHKznof"
]
}
}
]
}


posted @ 2019-06-14 22:33  KRDecad3  阅读(2042)  评论(0编辑  收藏  举报