Exemple #1
0
 def deserialize(self, buffer):
     decodedBuffer = RLP.decode(buffer)
     self.chainWork = DataType.deserialize(decodedBuffer[0], DataType.INT,
                                           0)
     self.previousHash = decodedBuffer[1]
     self.gasLimit = DataType.deserialize(decodedBuffer[2], DataType.INT, 0)
     self.height = DataType.deserialize(decodedBuffer[3], DataType.INT, 0)
 def deserialize(self, payload):
     if self.validatePayload(payload, 2):
         self.type = DataType.deserialize(payload[0])
         self.nonce = DataType.deserialize(payload[1], DataType.INT, 0)
         if self.validate():
             return True
     return False
 def deserialize(self, payload):
     if self.validatePayload(payload, 2):
         self.type = DataType.deserialize(payload[0])
         self.addrList = DataType.deserialize(payload[1], DataType.LIST, [])
         if self.validate():
             return True
     return False
Exemple #4
0
 def deserialize(self, buffer):
     decodedBuffer = RLP.decode(buffer)
     self.host = DataType.deserialize(decodedBuffer[0])
     self.version = DataType.deserialize(decodedBuffer[1])
     self.lastVersionNonce = DataType.deserialize(decodedBuffer[2], DataType.INT, None) 
     self.chainHeadBlockHash = decodedBuffer[3]
     self.lastUpdate = DataType.deserialize(decodedBuffer[4], DataType.INT, 0)
Exemple #5
0
 def deserialize(self, payload):
     if self.validatePayload(payload, 3):
         self.type = DataType.deserialize(payload[0])
         self.version = DataType.deserialize(payload[1], DataType.INT, 0)
         self.blockHashes = payload[2]
         if self.validate():
             return True
     return False
 def deserialize(self, buffer):
     decodedBuffer = RLP.decode(buffer)
     self.output = Output()
     self.output.deserialize(decodedBuffer[0])
     self.txOutputSize = DataType.deserialize(decodedBuffer[1],
                                              DataType.INT, 0)
     self.height = DataType.deserialize(decodedBuffer[2], DataType.INT, 0)
     self.coinbase = DataType.deserialize(decodedBuffer[3], DataType.BOOL,
                                          False)
 def deserialize(self, payload):
     if self.validatePayload(payload, 5):
         self.type = DataType.deserialize(payload[0])
         self.version = DataType.deserialize(payload[1])
         self.timestamp = DataType.deserialize(payload[2], DataType.INT, 0)
         self.nonce = DataType.deserialize(payload[3], DataType.INT, 0)
         self.chainHeadBlockHash = payload[4]
         if self.validate():
             return True
     return False
Exemple #8
0
 def deserialize(self, payload):
     if payload != None and len(payload) == 2:
         self.invType = DataType.deserialize(payload[0])
         self.invHash = payload[1]
         if self.validate():
             return True
     return False
def getInstance(msg):
    msgType = msg
    if isinstance(msg, list):
        msgType = DataType.deserialize(msg[0])
    '''Socket Messages Types'''
    if MessageType.ADDR == msgType:
        return Addr()
    elif MessageType.BLOCK == msgType:
        return Block()
    elif MessageType.GETADDR == msgType:
        return GetAddr()
    elif MessageType.GETBLOCKS == msgType:
        return GetBlocks()
    elif MessageType.GETDATA == msgType:
        return GetData()
    elif MessageType.INV == msgType:
        return Inv()
    elif MessageType.MEMPOOL == msgType:
        return MemPool()
    elif MessageType.PING == msgType:
        return Ping()
    elif MessageType.PONG == msgType:
        return Pong()
    elif MessageType.TX == msgType:
        return Tx()
    elif MessageType.VERACK == msgType:
        return VerAck()
    elif MessageType.VERSION == msgType:
        return Version()
Exemple #10
0
 def deserialize(self, payload):
     if self.validatePayload(payload, 2):
         self.type = DataType.deserialize(payload[0])
         self.transaction = payload[1]
         if self.validate():
             return True
     return False
 def deserialize(self, buffer):
     decodedBuffer = RLP.decode(buffer)
     self.version = DataType.deserialize(decodedBuffer[0], DataType.INT, 0)
     self.gasLimit = DataType.deserialize(decodedBuffer[2], DataType.INT, 0)
     self.gasPrice = DataType.deserialize(decodedBuffer[1], DataType.INT, 0)
     self.inputs = []
     for txInBuffer in decodedBuffer[3]:
         txIn = Input()
         txIn.deserialize(txInBuffer)
         self.inputs.append(txIn)
     self.outputs = []
     for txOutBuffer in decodedBuffer[4]:
         txOut = Output()
         txOut.deserialize(txOutBuffer)
         self.outputs.append(txOut)
     for txIn, witness in zip(self.inputs, decodedBuffer[5]):
         txIn.witness = witness
 def do_POST(self):
     if self.hasAuthorization():
         length = DataType.asInt(self.headers['Content-Length'])
         payload = self.rfile.read(length)
         payload = DataType.deserialize(payload)
         payload = json.loads(payload)
         self.handlePayload(payload)
     else:
         response = JSONRPC.createErrorObject(
             -32010, 'unauthorized',
             'you are not authorized to access this resource', None)
         self.writeResponse(response, doHead=False)
 def deserialize(self, payload):
     if self.validatePayload(payload, 2):
         self.type = DataType.deserialize(payload[0])
         inventoryBytes = payload[1]
         for invBytes in inventoryBytes:
             inventory = Inventory()
             invBytes = RLP.decode(invBytes)
             inventory.deserialize(invBytes)
             self.inventory.append(inventory)
         if self.validate():
             return True
     return False
Exemple #14
0
def getSocketPayload(
    socket, bufferSize=Config.getIntValue("SOCKET_HEADER_BUFFER_SIZE")):
    payload = b''
    payloadLen = None
    hasData = True
    while hasData:
        data = socket.recv(bufferSize)
        if payloadLen == None:
            payloadLen = DataType.deserialize(data, DataType.INT, 0)
            bufferSize = Config.getIntValue("SOCKET_RECEIVE_BUFFER_SIZE")
        else:
            dataLen = len(data)
            if dataLen > 0:
                payload += data
                if dataLen >= payloadLen:
                    hasData = False
                else:
                    payloadLen -= dataLen
            else:
                hasData = False
    return payload
 def deserialize(self, buffer):
     decodedBuffer = RLP.decode(buffer)
     self.version = DataType.deserialize(decodedBuffer[0], DataType.INT, 0)
     self.previousHash = decodedBuffer[1]
     self.merkleRoot = decodedBuffer[2]
     self.witnessRoot = decodedBuffer[3]
     self.gasLimit = DataType.deserialize(decodedBuffer[4], DataType.INT, 0)
     self.gasUsed = DataType.deserialize(decodedBuffer[5], DataType.INT, 0)
     self.nonce = DataType.deserialize(decodedBuffer[6], DataType.INT, 0)
     self.bits = DataType.deserialize(decodedBuffer[7], DataType.INT, 0)
     self.timestamp = DataType.deserialize(decodedBuffer[8], DataType.INT, 0)
     self.transactions = []
     for txBuffer in decodedBuffer[9]:
         transaction = Transaction()
         transaction.deserialize(txBuffer)
         self.transactions.append(transaction)
def getConfirmedBalanceByAddress(address):
    confirmedBalanceBytes = Accounts.index.get(address, Accounts.balancesSubDb)
    return DataType.deserialize(confirmedBalanceBytes, DataType.INT, 0)
 def deserialize(self, payload):
     if self.validatePayload(payload, 1):
         self.type = DataType.deserialize(payload[0])
         if self.validate():
             return True
     return False
 def deserialize(self, buffer):
     decodedBuffer = RLP.decode(buffer)
     self.txId = decodedBuffer[0]
     self.outputIndex = DataType.deserialize(decodedBuffer[1], DataType.INT,
                                             0)
Exemple #19
0
 def deserialize(self, buffer):
     decodedBuffer = RLP.decode(buffer)
     self.address = decodedBuffer[0]
     self.script = decodedBuffer[1]
     self.value = DataType.deserialize(decodedBuffer[2], DataType.INT, 0)
     self.extraData = decodedBuffer[3]