《区块链编程》第八章
支付到脚本哈希
练习1
p140
代码实现
# -*- coding: utf-8 -*-
# @Author: 从化北(喵星人)
# @Date: 2022-01-12 15:15:30
# @Last Modified by: 从化北
# @Last Modified time: 2022-01-12 15:15:30
def op_checkmultisig(stack, z):
if len(stack) < 1:
return False
n = decode_num(stack.pop())
if len(stack) < n + 1:
return False
sec_pubkeys = []
for _ in range(n):
sec_pubkeys.append(stack.pop())
m = decode_num(stack.pop())
if len(stack) < m + 1:
return False
der_signatures = []
for _ in range(m):
der_signatures.append(stack.pop()[:-1]) # <1>
stack.pop() # <2>
try:
# parse all the points
points = [S256Point.parse(sec) for sec in sec_pubkeys]
# parse all the signatures
sigs = [Signature.parse(der) for der in der_signatures]
# loop through the signatures
for sig in sigs:
# if we have no more points, signatures are no good
if len(points) == 0:
return False
# we loop until we find the point which works with this signature
while points:
# get the current point from the list of points