Пример #1
0
def get(key, readOnly):
    if readOnly:
        if key in PersistentStorage.storage:
            return PersistentStorage.storage[key]
        value = PersistentStorage.persistent.get(RLP.encode(key))
        if value != None:
            value = RLP.decode(value)
            PersistentStorage.storage[key] = value
            return value
    else:
        value = PersistentStorage.persistent.get(RLP.encode(key))
        if value != None:
            return RLP.decode(value)
    return None
Пример #2
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)
Пример #3
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)
Пример #4
0
 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)
Пример #5
0
 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
Пример #6
0
 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)
Пример #7
0
 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
Пример #8
0
def _sendData(host, data, hasPayload):
    try:
        if ':' in host:
            host = host.split(':')
            host[1] = DataType.asInt(host[1])
            host = tuple(host)
        else:
            host = (host, getSocketPort())
        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
            sock.connect(host)
            sock.settimeout(Config.getIntValue("CONNECTION_TIMEOUT"))
            data = DataType.serialize(data)
            dataLen = len(data)
            dataLen = DataType.intToBytes(
                dataLen, Config.getIntValue("SOCKET_HEADER_BUFFER_SIZE"))
            sock.sendall(dataLen)
            sock.sendall(data)
            if hasPayload:
                payload = getSocketPayload(sock)
                return RLP.decode(payload)
    except IOError:
        Log.error('Unable to send data to host: %s data: %s' % (host, data))
    return None
Пример #9
0
 def deserialize(self, buffer):
     decodedBuffer = RLP.decode(buffer)
     self.txId = decodedBuffer[0]
     self.outputIndex = DataType.deserialize(decodedBuffer[1], DataType.INT,
                                             0)
Пример #10
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]
Пример #11
0
 def deserialize(self, buffer):
     decodedBuffer = RLP.decode(buffer)
     self.outpoint = Outpoint()
     self.outpoint.deserialize(decodedBuffer[0])
Пример #12
0
 def handle(self):
     payload = Network.getSocketPayload(self.request)
     payload = RLP.decode(payload)
     self.handlePayload(payload)