本文整理汇总了Python中armoryengine.BinaryUnpacker.BinaryUnpacker类的典型用法代码示例。如果您正苦于以下问题:Python BinaryUnpacker类的具体用法?Python BinaryUnpacker怎么用?Python BinaryUnpacker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BinaryUnpacker类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: unserialize
def unserialize(self, toUnpack):
if isinstance(toUnpack, BinaryUnpacker):
addrData = toUnpack
else:
addrData = BinaryUnpacker( toUnpack )
self.addrList = []
naddr = addrData.get(VAR_INT)
for i in range(naddr):
self.addrList.append( PyNetAddress().unserialize(addrData) )
return self
示例2: unserialize
def unserialize(self, toUnpack):
if isinstance(toUnpack, BinaryUnpacker):
blkData = toUnpack
else:
blkData = BinaryUnpacker( toUnpack )
self.txList = []
self.numTx = blkData.get(VAR_INT)
for i in xrange(self.numTx):
self.txList.append( PyTx().unserialize(blkData) )
self.merkleTree = []
self.merkleRoot = ''
return self
示例3: executeScript
def executeScript(self, binaryScript, stack=[]):
self.stack = stack
self.stackAlt = []
scriptData = BinaryUnpacker(binaryScript)
self.lastOpCodeSepPos = None
while scriptData.getRemainingSize() > 0:
opcode = scriptData.get(UINT8)
exitCode = self.executeOpCode(opcode, scriptData, self.stack, self.stackAlt)
if not exitCode == SCRIPT_NO_ERROR:
if exitCode==OP_NOT_IMPLEMENTED:
LOGERROR('***ERROR: OpCodes OP_IF, OP_NOTIF, OP_ELSE, OP_ENDIF,')
LOGERROR(' have not been implemented, yet. This script')
LOGERROR(' could not be evaluated.')
if exitCode==OP_DISABLED:
LOGERROR('***ERROR: This script included an op code that has been')
LOGERROR(' disabled for security reasons. Script eval')
LOGERROR(' failed.')
return exitCode
return SCRIPT_NO_ERROR
示例4: unserialize
def unserialize(self, toUnpack):
if isinstance(toUnpack, BinaryUnpacker):
msgData = toUnpack
else:
msgData = BinaryUnpacker( toUnpack )
self.magic = msgData.get(BINARY_CHUNK, 4)
self.cmd = msgData.get(BINARY_CHUNK, 12).strip('\x00')
length = msgData.get(UINT32)
chksum = msgData.get(BINARY_CHUNK, 4)
payload = msgData.get(BINARY_CHUNK, length)
payload = verifyChecksum(payload, chksum)
self.payload = PayloadMap[self.cmd]().unserialize(payload)
if self.magic != MAGIC_BYTES:
raise NetworkIDError, 'Message has wrong network bytes!'
return self
示例5: dataReceived
def dataReceived(self, data):
"""
Called by the reactor when data is received over the connection.
This method will do nothing if we don't receive a full message.
"""
#print '\n\nData Received:',
#pprintHex(binary_to_hex(data), withAddr=False)
# Put the current buffer into an unpacker, process until empty
self.recvData += data
buf = BinaryUnpacker(self.recvData)
messages = []
while True:
try:
# recvData is only modified if the unserialize succeeds
# Had a serious issue with references, so I had to convert
# messages to strings to guarantee that copies were being
# made! (yes, hacky...)
thisMsg = PyMessage().unserialize(buf)
messages.append( thisMsg.serialize() )
self.recvData = buf.getRemainingString()
except NetworkIDError:
LOGERROR('Message for a different network!' )
if BLOCKCHAINS.has_key(self.recvData[:4]):
LOGERROR( '(for network: %s)', BLOCKCHAINS[self.recvData[:4]])
# Before raising the error, we should've finished reading the msg
# So pop it off the front of the buffer
self.recvData = buf.getRemainingString()
return
except UnknownNetworkPayload:
return
except UnpackerError:
# Expect this error when buffer isn't full enough for a whole msg
break
# We might've gotten here without anything to process -- if so, bail
if len(messages)==0:
return
# Finally, we have some message to process, let's do it
for msgStr in messages:
msg = PyMessage().unserialize(msgStr)
cmd = msg.cmd
# Log the message if netlog option
if CLI_OPTIONS.netlog:
LOGDEBUG( 'DataReceived: %s', msg.payload.command)
if msg.payload.command == 'tx':
LOGDEBUG('\t' + binary_to_hex(msg.payload.tx.thisHash))
elif msg.payload.command == 'block':
LOGDEBUG('\t' + msg.payload.header.getHashHex())
elif msg.payload.command == 'inv':
for inv in msg.payload.invList:
LOGDEBUG(('\tBLOCK: ' if inv[0]==2 else '\tTX : ') + \
binary_to_hex(inv[1]))
# We process version and verackk only if we haven't yet
if cmd=='version' and not self.sentVerack:
self.peerInfo = {}
self.peerInfo['version'] = msg.payload.version
self.peerInfo['subver'] = msg.payload.subver
self.peerInfo['time'] = msg.payload.time
self.peerInfo['height'] = msg.payload.height0
LOGINFO('Received version message from peer:')
LOGINFO(' Version: %s', str(self.peerInfo['version']))
LOGINFO(' SubVersion: %s', str(self.peerInfo['subver']))
LOGINFO(' TimeStamp: %s', str(self.peerInfo['time']))
LOGINFO(' StartHeight: %s', str(self.peerInfo['height']))
self.sentVerack = True
self.sendMessage( PayloadVerack() )
elif cmd=='verack':
self.gotVerack = True
self.factory.handshakeFinished(self)
#self.startHeaderDL()
####################################################################
# Don't process any other messages unless the handshake is finished
if self.gotVerack and self.sentVerack:
self.processMessage(msg)