Skip to content

Instantly share code, notes, and snippets.

@dannynash
Last active July 27, 2018 08:59
Show Gist options
  • Save dannynash/6350c996e9571f2bf07a95fa3d731a9b to your computer and use it in GitHub Desktop.
Save dannynash/6350c996e9571f2bf07a95fa3d731a9b to your computer and use it in GitHub Desktop.
bitcoin 初探

Bitcoin

名詞解釋

formated block https://webbtc.com/block/000000000000000001f942eb4bfa0aeccb6a14c268f4c72d5fff17270da771b9

raw block https://blockchain.info/block/000000000000000001f942eb4bfa0aeccb6a14c268f4c72d5fff17270da771b9?format=hex

transaction in block (coinbase transaction) https://webbtc.com/tx/9a223b09449cdd383206db29fe7f5ea31e0154d9fb30eabafe36eb8a9a33d22f

UTXO: 存在 memory 當中 類似 stack

transaction example

Input:
Previous tx: f5d8ee39a430901c91a5917b9f2dc19d6d1a0e9cea205b009ca73dd04470b9a6
Index: 0
scriptSig: 304502206e21798a42fae0e854281abd38bacd1aeed3ee3738d9e1446618c4571d10
90db022100e2ac980643b0b82c0e88ffdfec6b64e3e6ba35e7ba5fdd7d5d6cc8d25c6b241501

Output:
Value: 5000000000
scriptPubKey: OP_DUP OP_HASH160 404371705fa9bd789a2fcd52d2c580b65d35549d
OP_EQUALVERIFY OP_CHECKSIG
  • input 跟 output value 會相同

  • input 會指名來源的上一個 transaction id

  • scriptSig 存在 input 當中

  • scriptPubKey 存在 output 中

執行時 scriptSig scriptPubKey 會合併起來到 stack 中執行

至於如何執行,下面的 script 介紹有不同的例子

About Script

https://en.bitcoin.it/wiki/Script#Opcodes

Standard Transaction to Bitcoin address (pay-to-pubkey-hash) (P2PKH)

  • scriptPubKey: OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG
  • scriptSig:

=> OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG

Obsolete pay-to-pubkey transaction (P2PK)

  • scriptPubKey: OP_CHECKSIG
  • scriptSig:

=> OP_CHECKSIG

P2SH

P2WPKH (Pay to Witness Public Key Hash)

https://programmingblockchain.gitbooks.io/programmingblockchain/content/other_types_of_ownership/p2wpkh_pay_to_witness_public_key_hash.html

  • Segregated Witness (Segwit)
  • 取代 scriptSig 透過 witness
  • SegWit replaces the 1MB block-size limit with a 4MB block-weight limit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment