지금까지 직렬화된 트랜잭션을 파싱했습니다. 이제 반대의 경우, 즉 주어진 트랜잭션을 직렬화
하는 방법을 살펴보겠습니다. 먼저
TxOut
클래스부터 시작합니다.
classTxOut:
...
defserialize(self):
➊
'''Returns the byte serialization of the transaction output'''
result = int_to_little_endian(self.amount,8)
result +=self.script_pubkey.serialize()
return result
➊
TxOut
객체를
bytes
형으로 직렬화합니다.
다음은
TxIn
을 직렬화합니다.
classTxIn:
...
defserialize(self):
'''Returns the byte serialization of the transaction input'''
result =self.prev_tx[::-1]
result += int_to_little_endian(self.prev_index,4)
result +=self.script_sig.serialize()
result += int_to_little_endian(self.sequence,4)
return result
마지막으로
Tx
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.