Add isStandardOpReturnScript, retrieveOpReturnData to Script

This commit is contained in:
Shun Usami 2018-10-05 14:55:43 +09:00
parent 4470cd68d6
commit 04cc92bbcf
2 changed files with 16 additions and 1 deletions

View File

@ -30,6 +30,6 @@ type_name:
excluded:
type_body_length: 500
line_length: 300
file_length: 500
file_length: 1000
number_separator:
minimum_length: 5

View File

@ -254,6 +254,21 @@ public class Script {
return requirements.nSigRequired > 0
}
public var isStandardOpReturnScript: Bool {
guard chunks.count == 2 else {
return false
}
return opcode(at: 0) == .OP_RETURN
&& pushedData(at: 1) != nil
}
public var retrieveOpReturnData: Data? {
guard isStandardOpReturnScript else {
return nil
}
return pushedData(at: 1)
}
// If typical multisig tx is detected, sets requirements:
private func detectMultisigScript() {
// multisig script must have at least 4 ops ("OP_1 <pubkey> OP_1 OP_CHECKMULTISIG")