def serialize(self, vds=None): if not vds: vds = BCDataStream() serialize_input(vds, self.vin) vds.write(hash_decode(self.block_hash)) vds.write_int64(self.sig_time) vds.write_string(self.sig) return vds.input.encode('hex')
def serialize(self, vds=None): if not vds: vds = BCDataStream() # IPv4-mapped IPv6 address. vds.write('00000000000000000000ffff'.decode('hex')) ip = map(int, self.ip.split('.')) for i in ip: vds.write_uchar(i) # Ports are encoded as big-endian. vds._write_num('>H', self.port) return vds.input.encode('hex')
def merkle_branch_from_string(s): vds = BCDataStream() vds.write(s) #vds.write(raw.decode('hex')) hashes = [] n_hashes = vds.read_compact_size() for i in xrange(n_hashes): _hash = vds.read_bytes(32) hashes.append(hash_encode(_hash)) index = vds.read_int32() return hashes, index, s[vds.read_cursor:]
def serialize(self, vds=None): if not vds: vds = BCDataStream() serialize_input(vds, self.vin) self.addr.serialize(vds) vds.write_string(self.collateral_key.decode('hex')) vds.write_string(self.delegate_key.decode('hex')) vds.write_string(self.sig) vds.write_int64(self.sig_time) vds.write_uint32(self.protocol_version) self.last_ping.serialize(vds) vds.write_int64(self.last_dsq) return vds.input.encode('hex')
def get_hash(self): vds = BCDataStream() serialize_input(vds, self.vin) vds.write_string(self.collateral_key.decode('hex')) vds.write_int64(self.sig_time) return hash_encode(bitcoin.Hash(vds.input))
def deserialize(cls, raw): vds = BCDataStream() vds.write(raw.decode('hex')) vin = parse_input(vds) address = NetworkAddress.deserialize(vds) collateral_pubkey = vds.read_bytes( vds.read_compact_size()).encode('hex') delegate_pubkey = vds.read_bytes(vds.read_compact_size()).encode('hex') sig = vds.read_bytes(vds.read_compact_size()) sig_time = vds.read_int64() protocol_version = vds.read_uint32() last_ping = MasternodePing.deserialize(vds) last_dsq = vds.read_int64() kwargs = { 'vin': vin, 'addr': address, 'collateral_key': collateral_pubkey, 'delegate_key': delegate_pubkey, 'sig': sig, 'sig_time': sig_time, 'protocol_version': protocol_version, 'last_ping': last_ping, 'last_dsq': last_dsq } return cls(**kwargs)
def get_hash(self): vds = BCDataStream() vds.write_string(self.proposal_name) vds.write_string(self.proposal_url) vds.write_int32(self.start_block) vds.write_int32(self.end_block) vds.write_int64(self.payment_amount) vds.write_string(Transaction.pay_script(bitcoin.TYPE_ADDRESS, self.address).decode('hex')) return bitcoin.hash_encode(bitcoin.Hash(vds.input))
def tx_from_string(s): vds = BCDataStream() vds.write(s) #vds.write(raw.decode('hex')) d = {} d['version'] = vds.read_int32() n_vin = vds.read_compact_size() d['vin'] = [] for i in xrange(n_vin): txin = {} # dirty hack: add outpoint structure to get correct txid later outpoint_pos = vds.read_cursor txin['coinbase'] = vds.read_bytes( vds.read_compact_size()).encode('hex') txin['sequence'] = vds.read_uint32() d['vin'].append(txin) n_vout = vds.read_compact_size() d['vout'] = [] for i in xrange(n_vout): txout = {} txout['value'] = vds.read_int64() txout['scriptPubKey'] = vds.read_bytes( vds.read_compact_size()).encode('hex') d['vout'].append(txout) d['lockTime'] = vds.read_uint32() # compute txid # dirty hack to insert coinbase outpoint structure before hashing raw = s[0:outpoint_pos] COINBASE_OP = '0' * 64 + 'F' * 8 raw += (COINBASE_OP).decode('hex') raw += s[outpoint_pos:vds.read_cursor] d['txid'] = Hash(raw)[::-1].encode('hex') return d, s[vds.read_cursor:] # +1?
def tx_from_string(s): vds = BCDataStream() vds.write(s) #vds.write(raw.decode('hex')) d = {} d['version'] = vds.read_int32() n_vin = vds.read_compact_size() d['vin'] = [] for i in xrange(n_vin): txin = {} # dirty hack: add outpoint structure to get correct txid later outpoint_pos = vds.read_cursor txin['coinbase'] = vds.read_bytes(vds.read_compact_size()).encode('hex') txin['sequence'] = vds.read_uint32() d['vin'].append(txin) n_vout = vds.read_compact_size() d['vout'] = [] for i in xrange(n_vout): txout = {} txout['value'] = vds.read_int64() txout['scriptPubKey'] = vds.read_bytes(vds.read_compact_size()).encode('hex') d['vout'].append(txout) d['lockTime'] = vds.read_uint32() # compute txid # dirty hack to insert coinbase outpoint structure before hashing raw = s[0:outpoint_pos] COINBASE_OP = '0' * 64 + 'F' * 8 raw += (COINBASE_OP).decode('hex') raw += s[outpoint_pos:vds.read_cursor] d['txid'] = Hash(raw)[::-1].encode('hex') return d, s[vds.read_cursor:] # +1?