def push_bytes(data): ms = StreamManager.GetStream() writer = BinaryWriter(ms) if len(data) == 0: raise ValueError("push data error: data is null") if len(data) <= int.from_bytes(PUSHBYTES75, 'little') + 1 - int.from_bytes( PUSHBYTES1, 'little'): num = len(data) + int.from_bytes(PUSHBYTES1, 'little') - 1 writer.WriteByte(num) elif len(data) < 0x100: writer.WriteByte(PUSHDATA1) writer.WriteUInt8(len(data)) elif len(data) < 0x10000: writer.WriteByte(PUSHDATA2) writer.WriteUInt16(len(data)) else: writer.WriteByte(PUSHDATA4) writer.WriteUInt32(len(data)) writer.WriteBytes(data) ms.flush() res = ms.ToArray() StreamManager.ReleaseStream(ms) res = bytes_reader(res) return res
def serialize(self): ms = StreamManager.GetStream() writer = BinaryWriter(ms) writer.WriteBytes(self.serialize_unsigned()) writer.WriteVarInt(len(self.sigs)) for sig in self.sigs: writer.WriteBytes(sig.serialize()) ms.flush() temp = ms.ToArray() StreamManager.ReleaseStream(ms) return bytes_reader(temp)
def serialize(self): invoke_script = ProgramBuilder.program_from_params(self.sig_data) if len(self.public_keys) == 0: raise ValueError("np public key in sig") verification_script = ProgramBuilder.program_from_pubkey(self.public_keys[0]) ms = StreamManager.GetStream() writer = BinaryWriter(ms) writer.WriteVarBytes(invoke_script) writer.WriteVarBytes(verification_script) ms.flush() res = ms.ToArray() res = bytes_reader(res) StreamManager.ReleaseStream(ms) return res
def serialize(self): ms = StreamManager.GetStream() writer = BinaryWriter(ms) writer.WriteBytes(self.serialize_unsigned()) writer.WriteVarInt(len(self.sigs)) #temp = bytes_reader(temp) #tx_serial += temp for sig in self.sigs: #print(sig.M) #print(sig.public_keys) #print(sig.sig_data) writer.WriteBytes(sig.serialize()) #tx_serial += serial_sig ms.flush() temp = ms.ToArray() StreamManager.ReleaseStream(ms) return bytes_reader(temp)
def build_neo_vm_param(builder, params): if isinstance(params, dict): builder.emit_push_integer(0) builder.emit(NEWSTRUCT) builder.emit(TOALTSTACK) for i in params.values(): build_neo_vm_param(builder, i) builder.emit(DUPFROMALTSTACK) builder.emit(SWAP) builder.emit(APPEND) builder.emit(FROMALTSTACK) elif isinstance(params, str): builder.emit_push_byte_array(util.bytes_reader(params.encode())) elif isinstance(params, bytes): builder.emit_push_byte_array(params) elif isinstance(params, bytearray): builder.emit_push_byte_array(params) elif isinstance(params, int): builder.emit_push_integer(params) elif isinstance(params, list): build_neo_vm_param(builder, params[0]) builder.emit_push_integer(len(params)) builder.emit(PACK)
def hash256(self): tx_serial = self.serialize_unsigned() tx_serial = bytes_reader(tx_serial) r = Digest.hash256(tx_serial) r = Digest.hash256(r) return r