Input คืออะไร?

input

ข้อมูล Input ก็คือข้อมูล Output ที่นำมาใช้ในรายการธุรกรรม 

โครงสร้างของ INPUT

01000000017967a5185e907a25225574544c31f7b059c1a191d65b53dcc1554d339c4f9efc010000006a47304402206a2eb16b7b920
51d0fa38c133e67684ed064effada1d7f925c842da401d4f22702201f196b10e6e4b4a9fff948e5c5d71ec5da53e90529c8dbd122bf
f2b1d21dc8a90121039b7bcd0824b9a9164f7ba098408e63e5b7e3cf90835cceb19868f54f8961a825
ffffffff
014baf21000000000
0
1976a914db4d1141d0048b1ed15839d0b7a4c488cd368b0e88ac
00000000

Fields

Field

Data

Size

Description

TXID

796…efc

32 bytes

อ้างอิงถึงรายการธุรกรรมบนเครือข่าย

VOUT

01000000

4 bytes

 เลือกข้อมูล output จำนวน 1 รายการ

ScriptSig Size

6a

Variable

ตัวแปร บ่งชี้ขนาดของ Code สำหรับปลดล็อกที่กำลังจะเกิดขึ้น

ScriptSig

473…825

สคริปต์ที่ปลดล็อกข้อมูล Input

Sequence

ffffffff

4 bytes

TXID Byte Order: เมื่อเราอ้างถึง TXID ภายในข้อมูลรายการธุรกรรม คุณจะต้องย้อนกลับคำสั่งไบต์ (reverse the byte order) เพื่อรับรูปแบบดั้งเดิมของข้อมูลดังกล่าว  คำสั่งไบต์จะใช้เมื่อมีการค้นหา TXID ที่อยู่ในรูปแบบย้อนกลับ (เนื่องจากความผิดพลาดในอดีตในรูปแบบการทำงานของโปรแกรม Bitcoin ดั้งเดิม)

ข้อมูล Input ทำงานอย่างไร?

ข้อมูล Input จะมี 2 หน้าที่ด้วยกัน 

  1. เลือกข้อมูล Output 
  2. ปลดล็อกมัน

1. เลือกข้อมูล Output

เมื่อคุณต้องการใช้ข้อมูล Output เพื่อเป็นข้อมูล Input ในการทำธุกรรม คุณแค่ต้องระบุว่ข้อมูลใดที่คุณต้องการจะใช้งาน 

ทุกๆ รายการธุรกรรมจะมี TXID ที่ไม่เหมือนกัน เพราะฉะนั้น ด้วยการใช้ข้อมูลดังกล่าวกับเลข Output เฉพาะ (VOUT) คุณจะสามารถอ้างถึงข้อมูล Output ใดๆ ก็ได้บน Blockchain

reference

คุณแค่ต้องใช้ txid และ vout และคุณก็จะสามารถเลือกข้อมูล Output ใดก็ได้ที่อยู่บน Blockchain

2. ปลดล็อกมัน

หลังจากที่เจอข้อมูล Output แล้ว จากนั้นคุณก็แค่ต้องปลดล็อกมัน 

ข้อมูล Output แต่ละข้อมูลถูกตั้งค่าไว้ด้วยสคริปต์สำหรับล็อก (Locking Script) เพราะฉะนั้น หากคุณต้องการที่จะใช้รายการใดรายการหนึ่ง คุณต้องใส่สคริปต์สำหรับปลดล็อก (unlocking Script) ซึ่งเรียกว่า ScriptSig

unlocking

Notes

Listunspent

คำสั่งนี้จะทำให้คุณสามารถตรวจสอบรายการของข้อมูล Output ที่ยังไม่ถูกใช้งานในกระเป๋าสตางค์ Bitcoin แบบ Cold wallet ของคุณ 

อีกนัยหนึ่งก็คือมันจะแสดงรายการข้อมูล Output ที่คุณสามารถใช้เป็นข้อมูล Input ในรายการธุรกรรมใหม่ 

$ bitcoin-cli listunspent

[
  {
    "txid" : "txid",          (string) the transaction id
    "vout" : n,               (numeric) the vout value
    "address" : "address",    (string) the bitcoin address
    "account" : "account",    (string) DEPRECATED. The associated account, or "" for the default account
    "scriptPubKey" : "key",   (string) the script key
    "amount" : x.xxx,         (numeric) the transaction output amount in BTC
    "confirmations" : n,      (numeric) The number of confirmations
    "redeemScript" : n        (string) The redeemScript if scriptPubKey is P2SH
    "spendable" : xxx,        (bool) Whether we have the private keys to spend this output
    "solvable" : xxx,         (bool) Whether we know how to spend this output, ignoring the lack of keys
    "safe" : xxx              (bool) Whether this output is considered safe to spend. Unconfirmed transactions
                              from outside keys and unconfirmed replacement transactions are considered unsafe
                              and are not eligible for spending by fundrawtransaction and sendtoaddress.
  }
  ,...
]