Fix op_return push

This commit is contained in:
Christian Nyumbayire 2017-05-07 02:45:37 +02:00
parent a77abd4545
commit e6958468c3
1 changed files with 9 additions and 0 deletions

View File

@ -102,7 +102,16 @@ impl Builder {
/// Appends `OP_RETURN` operation to the end of script
pub fn return_bytes(mut self, bytes: &[u8]) -> Self {
let len = bytes.len();
if len < 1 || len > 75 {
panic!(format!("Canot push {} bytes", len));
}
let opcode: Opcode = Opcode::from_u8(((Opcode::OP_PUSHBYTES_1 as usize) + len - 1) as u8)
.expect("value is within [OP_PUSHBYTES_1; OP_PUSHBYTES_75] interval; qed");
self.data.push(Opcode::OP_RETURN as u8);
self.data.push(opcode as u8);
self.data.extend_from_slice(bytes);
self
}