当前位置: 首页>>代码示例>>Python>>正文


Python core.CBlock类代码示例

本文整理汇总了Python中bitcoin.core.CBlock的典型用法代码示例。如果您正苦于以下问题:Python CBlock类的具体用法?Python CBlock怎么用?Python CBlock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CBlock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

 def __init__(self):
     self.blockcount = 0
     self.rawmempool = {}
     self.on = True
     self._blockhashes, blocks_ser = load_obj(blockdata)
     self._blocks = {}
     for blockhash, block_ser in blocks_ser.items():
         self._blocks[blockhash] = CBlock.deserialize(block_ser)
开发者ID:OverlordQ,项目名称:bitcoin-feemodel,代码行数:8,代码来源:pseudoproxy.py

示例2: submitblock

    def submitblock(self, params):
        err = { "code" : -1, "message" : "invalid params" }
        if (len(params) != 1 or
            (not isinstance(params[0], str) and
             not isinstance(params[0], unicode))):
            return (None, err)

        data = params[0].decode('hex')
        f = cStringIO.StringIO(data)
        block = CBlock()
        block.deserialize(f)

        res = self.chaindb.putblock(block)
        if not res:
            return ("rejected", None)

        return (None, None)
开发者ID:obulpathi,项目名称:reversecoin,代码行数:17,代码来源:rpc.py

示例3: msg_block

class msg_block(MsgSerializable):
    command = b"block"

    def __init__(self, protover=PROTO_VERSION):
        super(msg_block, self).__init__(protover)
        self.block = CBlock()

    @classmethod
    def msg_deser(cls, f, protover=PROTO_VERSION):
        c = cls()
        c.block = CBlock.stream_deserialize(f)
        return c

    def msg_ser(self, f):
        self.block.stream_serialize(f)

    def __repr__(self):
        return "msg_block(block=%s)" % (repr(self.block))
开发者ID:ghtdak,项目名称:python-bitcoinlib,代码行数:18,代码来源:messages.py

示例4: loadfile

def loadfile(filename):
    fd = os.open(filename, os.O_RDONLY)
    print("IMPORTING DATA FROM " + filename)
    buf = ''
    wanted = 4096
    while True:
        if wanted > 0:
            if wanted < 4096:
                wanted = 4096
            s = os.read(fd, wanted)
            if len(s) == 0:
                break

            buf += s
            wanted = 0

        buflen = len(buf)
        startpos = string.find(buf, netmagic)
        startpos = 0
        if startpos < 0:
            wanted = 8
            continue

        sizepos = startpos + 4
        blkpos = startpos + 8
        if blkpos > buflen:
            wanted = 8
            continue

        blksize = struct.unpack("<i", buf[sizepos:blkpos])[0]
        print "blkpos: ", blkpos, "blksize: ", blksize, "buflen: ", buflen
        if (blkpos + blksize) > buflen:
            wanted = 8 + blksize
            continue

        ser_blk = buf[blkpos:blkpos+blksize]
        buf = buf[blkpos+blksize:]

        f = cStringIO.StringIO(ser_blk)
        block = CBlock()
        block.deserialize(f)
        print block
开发者ID:davidsoloman,项目名称:blockchain,代码行数:42,代码来源:dump_blkchain.py

示例5: test_path_from_txid_to_merkleroot

    def test_path_from_txid_to_merkleroot(self):

        def T(blk):
            merkle_root = blk.calc_merkle_root()
            for tx in blk.vtx:
                txid = tx.GetHash()
                path = path_from_txid_to_merkleroot(txid, blk)
                self.assertEqual(path(txid), merkle_root)

        # Block with two transactions in it
        blk170 = CBlock.deserialize(x('0100000055bd840a78798ad0da853f68974f3d183e2bd1db6a842c1feecf222a00000000ff104ccb05421ab93e63f8c3ce5c2c2e9dbb37de2764b3a3175c8166562cac7d51b96a49ffff001d283e9e700201000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0704ffff001d0102ffffffff0100f2052a01000000434104d46c4968bde02899d2aa0963367c7a6ce34eec332b32e42e5f3407e052d64ac625da6f0718e7b302140434bd725706957c092db53805b821a85b23a7ac61725bac000000000100000001c997a5e56e104102fa209c6a852dd90660a20b2d9c352423edce25857fcd3704000000004847304402204e45e16932b8af514961a1d3a1a25fdf3f4f7732e9d624c6c61548ab5fb8cd410220181522ec8eca07de4860a4acdd12909d831cc56cbbac4622082221a8768d1d0901ffffffff0200ca9a3b00000000434104ae1a62fe09c5f51b13905f07f06b99a2f7159b2225f374cd378d71302fa28414e7aab37397f554a7df5f142c21c1b7303b8a0626f1baded5c72a704f7e6cd84cac00286bee0000000043410411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3ac00000000'))
        T(blk170)

        # 99960 three transactions
        blk_3tx = CBlock.deserialize(x('01000000e78b20013e6e9a21b6366ead5d866b2f9dc00664508b90f24da8000000000000f94b61259c7e9af3455b277275800d0d6a58b929eedf9e0153a6ef2278a5d53408d11a4d4c86041b0fbf10b00301000000010000000000000000000000000000000000000000000000000000000000000000ffffffff07044c86041b0119ffffffff0100f2052a0100000043410427e729f9cb5564abf2a1ccda596c636b77bd4d9d91f657d4738f3c70fce8ac4e12b1c782905554d9ff2c2e050fdfe3ff93c91c5817e617877d51f450b528c9e4ac000000000100000001e853c9e0c133547fd9e162b1d3860dd0f27d5b9b8a7430d28896c00fbb3f1bc7000000008c49304602210095bcd54ebd0caa7cee75f0f89de472a765e6ef4b98c5fd4b32c7f9d4905db9ae022100ebd3f668e3a1a36d56e30184c27531dbb9fc136c84b1282be562064d86997d1e014104727eb4fdcc90658cd26abe7dcb0ae7297810b15b9e27c32bcf8e3edd934901968806dc18b1276d7273cc4c223feee0070361ed947888a3cef422bebfede96e08ffffffff020065cd1d000000001976a91468c6c2b3c0bc4a8eeb10d16a300d627a31a3b58588ac0008af2f000000001976a9141d87f0a54a1d704ffc70eae83b025698bc0fdcfc88ac00000000010000000125f582f1d37b6713b14b85665a2daea4f464f5ed1c3ab3d4dcf152fb61414b9e000000008a473044022066ec12ced31659e1bf961b542b58bba76ba8f2a1e8f36d5f60be0601598eac21022047ce33685a63283a4c3ebc390261191f215999b2f7d8e1504b8af39aae4a2881014104c5e1d713d10fe59cc48f60701a3efcac418969c22e9c6cf57440f71e44dc82837af5351bf3e1d898f06aa5c792bf0251a39902311d1d27c16847b1b414494f35ffffffff02404b4c00000000001976a91466a3b2e43cfa5c6d9b2f0095f7be5a5cb608478c88ac80b8dc3c030000001976a9146df5ed8cee34df5c05c90406761a11ed143c202d88ac00000000'))
        T(blk_3tx)

        # 99993 four transactions
        blk_4tx = CBlock.deserialize(x('01000000acda3db591d5c2c63e8c09e7523a5b0581707ef3e3520d6ca180000000000000701179cb9a9e0fe709cc96261b6b943b31362b61dacba94b03f9b71a06cc2eff7d1c1b4d4c86041b75962f880401000000010000000000000000000000000000000000000000000000000000000000000000ffffffff07044c86041b0152ffffffff014034152a01000000434104216220ab283b5e2871c332de670d163fb1b7e509fd67db77997c5568e7c25afd988f19cd5cc5aec6430866ec64b5214826b28e0f7a86458073ff933994b47a5cac0000000001000000042a40ae58b06c3a61ae55dbee05cab546e80c508f71f24ef0cdc9749dac91ea5f000000004a49304602210089c685b37903c4aa62d984929afeaca554d1641f9a668398cd228fb54588f06b0221008a5cfbc5b0a38ba78c4f4341e53272b9cd0e377b2fb740106009b8d7fa693f0b01ffffffff7b999491e30af112b11105cb053bc3633a8a87f44740eb158849a76891ff228b00000000494830450221009a4aa8663ff4017063d2020519f2eade5b4e3e30be69bf9a62b4e6472d1747b2022021ee3b3090b8ce439dbf08a5df31e2dc23d68073ebda45dc573e8a4f74f5cdfc01ffffffffdea82ec2f9e88e0241faa676c13d093030b17c479770c6cc83239436a4327d49000000004a493046022100c29d9de71a34707c52578e355fa0fdc2bb69ce0a957e6b591658a02b1e039d69022100f82c8af79c166a822d305f0832fb800786d831aea419069b3aed97a6edf8f02101fffffffff3e7987da9981c2ae099f97a551783e1b21669ba0bf3aca8fe12896add91a11a0000000049483045022100e332c81781b281a3b35cf75a5a204a2be451746dad8147831255291ebac2604d02205f889a2935270d1bf1ef47db773d68c4d5c6a51bb51f082d3e1c491de63c345601ffffffff0100c817a8040000001976a91420420e56079150b50fb0617dce4c374bd61eccea88ac00000000010000000265a7293b2d69ba51d554cd32ac7586f7fbeaeea06835f26e03a2feab6aec375f000000004a493046022100922361eaafe316003087d355dd3c0ef3d9f44edae661c212a28a91e020408008022100c9b9c84d53d82c0ba9208f695c79eb42a453faea4d19706a8440e1d05e6cff7501fffffffff6971f00725d17c1c531088144b45ed795a307a22d51ca377c6f7f93675bb03a000000008b483045022100d060f2b2f4122edac61a25ea06396fe9135affdabc66d350b5ae1813bc6bf3f302205d8363deef2101fc9f3d528a8b3907e9d29c40772e587dcea12838c574cb80f801410449fce4a25c972a43a6bc67456407a0d4ced782d4cf8c0a35a130d5f65f0561e9f35198349a7c0b4ec79a15fead66bd7642f17cc8c40c5df95f15ac7190c76442ffffffff0200f2052a010000001976a914c3f537bc307c7eda43d86b55695e46047b770ea388ac00cf7b05000000001976a91407bef290008c089a60321b21b1df2d7f2202f40388ac0000000001000000014ab7418ecda2b2531eef0145d4644a4c82a7da1edd285d1aab1ec0595ac06b69000000008c493046022100a796490f89e0ef0326e8460edebff9161da19c36e00c7408608135f72ef0e03e0221009e01ef7bc17cddce8dfda1f1a6d3805c51f9ab2f8f2145793d8e85e0dd6e55300141043e6d26812f24a5a9485c9d40b8712215f0c3a37b0334d76b2c24fcafa587ae5258853b6f49ceeb29cd13ebb76aa79099fad84f516bbba47bd170576b121052f1ffffffff0200a24a04000000001976a9143542e17b6229a25d5b76909f9d28dd6ed9295b2088ac003fab01000000001976a9149cea2b6e3e64ad982c99ebba56a882b9e8a816fe88ac00000000'))
        T(blk_4tx)
开发者ID:ilBOMBER87,项目名称:python-opentimestamps,代码行数:20,代码来源:test_blockchain.py

示例6: getwork_submit

    def getwork_submit(self, hexstr):
        data = hexstr.decode('hex')
        if len(data) != 128:
            err = { "code" : -5, "message" : "invalid data" }
            return (None, err)

        data = bufreverse(data)
        blkhdr = data[:80]
        # why are we passing blkheader for constructing block, should not we pass the whole block"
        # f = cStringIO.StringIO(blkhdr)
        f = cStringIO.StringIO(data)
        block_tmp = CBlock()
        block_tmp.deserialize(f)

        if block_tmp.hashMerkleRoot not in self.work_blocks:
            return (False, None)

        block = self.work_blocks[block_tmp.hashMerkleRoot]
        block.nTime = block_tmp.nTime
        block.nNonce = block_tmp.nNonce

        res = self.chaindb.putblock(block)

        return (res, None)
开发者ID:sachinm,项目名称:bitcoinpy,代码行数:24,代码来源:rpc.py

示例7: getblock

    def getblock(self, block_hash):
        """Get block <block_hash>

        Raises IndexError if block_hash is not valid.
        """
        try:
            block_hash = b2lx(block_hash)
        except TypeError:
            raise TypeError('%s.getblock(): block_hash must be bytes; got %r instance' %
                    (self.__class__.__name__, block_hash.__class__))
        try:
            r = self._call('getblock', block_hash, False)
        except JSONRPCException as ex:
            raise IndexError('%s.getblock(): %s (%d)' %
                    (self.__class__.__name__, ex.error['message'], ex.error['code']))
        return CBlock.deserialize(unhexlify(r))
开发者ID:jimmy0x52,项目名称:python-bitcoinlib,代码行数:16,代码来源:rpc.py

示例8: provide_block

	def provide_block(self, block_data):
		"""THIS METHOD WILL BLOCK UNTIL SENDING IS COMPLETE"""
		tx_count, read_pos = decode_varint(block_data, 80)
		self.send_lock.acquire()
		try:
			relay_data = pack('>3I', self.MAGIC_BYTES, self.BLOCK_TYPE, tx_count) + block_data[0:80]
			wire_bytes = 3 * 4 + 80
			for i in range(0, tx_count):
				tx_start = read_pos
				read_pos += 4

				tx_in_count, read_pos = decode_varint(block_data, read_pos)
				for j in range(0, tx_in_count):
					read_pos += 36
					script_len, read_pos = decode_varint(block_data, read_pos)
					read_pos += script_len + 4

				tx_out_count, read_pos = decode_varint(block_data, read_pos)
				for j in range(0, tx_out_count):
					read_pos += 8
					script_len, read_pos = decode_varint(block_data, read_pos)
					read_pos += script_len

				read_pos += 4

				transaction_data = block_data[tx_start:read_pos]
				tx_index = self.send_transaction_cache.get_index(transaction_data)
				if tx_index is None:
					relay_data += pack('>H', 0xffff) + pack('>HB', len(transaction_data) >> 8, len(transaction_data) & 0xff) + transaction_data
					wire_bytes += 2 + 3 + len(transaction_data)
				else:
					relay_data += pack('>H', tx_index)
					wire_bytes += 2
					self.send_transaction_cache.remove(transaction_data)

			relay_data += pack('>3I', self.MAGIC_BYTES, self.END_BLOCK_TYPE, 0)
			self.relay_sock.sendall(relay_data)

			if deserialize_utils:
				block = CBlock.deserialize(block_data)
				print("Sent block " + str(b2lx(block.GetHash())) + " of size " + str(len(block_data)) + " with " + str(wire_bytes) + " bytes on the wire")
			else:
				print("Sent block of size " + str(len(block_data)) + " with " + str(wire_bytes) + " bytes on the wire")
		except (OSError, socket.error) as err:
			print("Failed to send to relay node: ", err)
		finally:
			self.send_lock.release()
开发者ID:fudong1127,项目名称:RelayNode,代码行数:47,代码来源:RelayNetworkClient.py

示例9: getblock

    def getblock(self, block_hash):
        """Get block <block_hash>

        Raises IndexError if block_hash is not valid.
        """
        try:
            block_hash = b2lx(block_hash)
        except TypeError:
            raise TypeError('%s.getblock(): block_hash must be bytes; got %r instance' %
                    (self.__class__.__name__, block_hash.__class__))
        try:
            # With this change ( https://github.com/bitcoin/bitcoin/commit/96c850c20913b191cff9f66fedbb68812b1a41ea#diff-a0c8f511d90e83aa9b5857e819ced344 ),
            # bitcoin core's rpc takes 0/1/2 instead of true/false as the 2nd argument which specifies verbosity, since v0.15.0.
            # The change above is backward-compatible so far; the old "false" is taken as the new "0".
            r = self._call('getblock', block_hash, False)
        except InvalidAddressOrKeyError as ex:
            raise IndexError('%s.getblock(): %s (%d)' %
                    (self.__class__.__name__, ex.error['message'], ex.error['code']))
        return CBlock.deserialize(unhexlify(r))
开发者ID:petertodd,项目名称:python-bitcoinlib,代码行数:19,代码来源:rpc.py

示例10: deserialize

    def deserialize(self, raw):
        """Deserialize hex-encoded block/block header."""
        only_header = False
        if len(raw) == 160:
            only_header = True

        block = None
        block_header = None

        try:
            if only_header:
                block_header = CBlockHeader.deserialize(x(raw))
            else:
                # We don't use block.get_header() in case the header is
                # correct but the rest of the block isn't.
                block_header = CBlockHeader.deserialize(x(raw[0:160]))
                block = CBlock.deserialize(x(raw))
        except Exception:
            pass

        return (block, block_header)
开发者ID:oktoshi,项目名称:hashmal,代码行数:21,代码来源:block_analyzer.py

示例11: provide_block

	def provide_block(self, block_data):
		# THIS METHOD WILL BLOCK UNTIL SENDING IS COMPLETE
		tx_count, read_pos = decode_varint(block_data, 80)
		self.send_lock.acquire()
		try:
			txn_bytes = []
			for i in range(0, tx_count):
				tx_start = read_pos

				tx_in_count, read_pos = decode_varint(block_data, read_pos + 4)
				for j in range(0, tx_in_count):
					script_len, read_pos = decode_varint(block_data, read_pos + 36)
					read_pos += script_len + 4

				tx_out_count, read_pos = decode_varint(block_data, read_pos)
				for j in range(0, tx_out_count):
					script_len, read_pos = decode_varint(block_data, read_pos + 8)
					read_pos += script_len

				read_pos += 4

				txn_bytes.append(block_data[tx_start:read_pos])

			send_data = pack('>3I', self.MAGIC_BYTES, self.BLOCK_TYPE, tx_count) + block_data[0:80] + b''.join((self.compress_tx(t) for t in txn_bytes))
			self.relay_sock.sendall(send_data)
			self.relay_sock.sendall(pack('>3I', self.MAGIC_BYTES, self.END_BLOCK_TYPE, 0))

			if deserialize_utils:
				block = CBlock.deserialize(block_data)
				print("Sent block " + str(b2lx(block.GetHash())) + " of size " + str(len(block_data)) + " with " + str(len(send_data)) + " bytes on the wire")
			else:
				print("Sent block of size " + str(len(block_data)) + " with " + str(len(send_data)) + " bytes on the wire")
		except (OSError, socket.error) as err:
			print("Failed to send to relay node: ", err)
			self.relay_sock.shutdown(socket.SHUT_RDWR)
		finally:
			self.send_lock.release()
开发者ID:1024kb1,项目名称:RelayNode,代码行数:37,代码来源:RelayNetworkClient.py

示例12: msg_deser

 def msg_deser(cls, f, protover=PROTO_VERSION):
     c = cls()
     c.block = CBlock.stream_deserialize(f)
     return c
开发者ID:ghtdak,项目名称:python-bitcoinlib,代码行数:4,代码来源:messages.py

示例13: getblock

def getblock(block_hash):
    block_hex = BACKEND().getblock(block_hash)
    return CBlock.deserialize(util.unhexlify(block_hex))
开发者ID:tokenly,项目名称:counterparty-lib,代码行数:3,代码来源:__init__.py

示例14: xrange

log = Log.Log(SETTINGS['log'])
mempool = MemPool.MemPool(log)
chaindb = ChainDb.ChainDb(SETTINGS['db'], log, mempool, NETWORKS[MY_NETWORK])

scanned = 0
failures = 0

for height in xrange(chaindb.getheight()):
	heightidx = ChainDb.HeightIdx()
	heightidx.deserialize(chaindb.height[str(height)])

	blkhash = heightidx.blocks[0]
	ser_hash = ser_uint256(blkhash)

	f = cStringIO.StringIO(chaindb.blocks[ser_hash])
	block = CBlock()
	block.deserialize(f)

	if not block.is_valid():
		log.write("block %064x failed" % (blkhash,))
		failures += 1

	scanned += 1
	if (scanned % 1000) == 0:
		log.write("Scanned height %d (%d failures)" % (
			height, failures))


log.write("Scanned %d blocks (%d failures)" % (scanned, failures))

开发者ID:Ademan,项目名称:pynode,代码行数:29,代码来源:dbck.py

示例15: loadfile

def loadfile(filename,start,end,chaindb):
	fd = os.open(filename, os.O_RDONLY)
	#self.log.write("IMPORTING DATA FROM " + filename)
	buf = ''
	wanted = 4096

	count = 1

	while True:
		if wanted > 0:
			if wanted < 4096:
				wanted = 4096
			s = os.read(fd, wanted)
			if len(s) == 0:
				break

			buf += s
			wanted = 0

		buflen = len(buf)
		startpos = string.find(buf, msg_start)
		if startpos < 0:
			wanted = 8
			continue

		sizepos = startpos + 4
		blkpos = startpos + 8
		if blkpos > buflen:
			wanted = 8
			continue

		blksize = struct.unpack("<i", buf[sizepos:blkpos])[0]
		if (blkpos + blksize) > buflen:
			wanted = 8 + blksize
			continue

		ser_blk = buf[blkpos:blkpos+blksize]
		buf = buf[blkpos+blksize:]

		f = cStringIO.StringIO(ser_blk)
		block = CBlock()
		block.deserialize(f)

		count += 1

		skip_load = (count < start)
		if skip_load:
			if ((count % 10000) == 0):
				print "skiping: %d" % count
			continue

		if (end > -1) and (count >= end):
			print "Exit!"
			sys.exit(0)	

		ret = chaindb.putblock(block)

		height = chaindb.getheight()

		#if count == 778:
		#	print repr(block)

		heightidx = ChainDb.HeightIdx()
                heightidx.deserialize(chaindb.height(str(height)))
                blkhash = heightidx.blocks[0]



		skiped = False
		scanned = False
		
		#skip_scan = (height < skip_scan_height)	
		#if not skip_scan:
		#	if ret:
		#		scanned = scan_vtx(chaindb,block)
		
		strBlkHash = hex(blkhash).replace('0x','').replace('L','')
		print "Count: %d Putblock: %s Height: %d BlockHash: %s" % (count,ret,height,strBlkHash)

	print "tell: %d" % fd.tell()
	return count
开发者ID:BTCtools,项目名称:python-bitcoin_r,代码行数:81,代码来源:stage1.py


注:本文中的bitcoin.core.CBlock类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。