def __init__(self): super().__init__() self.type = MessageType.VERSION self.version = Config.getValue("NODE_VERSION") self.timestamp = DataType.asTime() self.nonce = randint(0, sys.maxsize) self.chainHeadBlockHash = None
def __init__(self): self.version = Config.getIntValue("BLOCK_VERSION") self.previousHash = None self.merkleRoot = None self.witnessRoot = None self.gasLimit = None self.gasUsed = None self.nonce = None self.bits = None self.timestamp = DataType.asTime() self.transactions = []
def addPeers(peers): for peer in peers: if peer.host != Peers.hostname and peer.host != Peers.ipAddress: currPeer = getPeerByHost(peer.host) synchronized = False if currPeer == None: currPeer = peer else: currPeer.merge(peer) synchronized = True currPeer.lastUpdate = DataType.asTime() hostBytes = DataType.serialize(currPeer.host) Peers.peers.set(hostBytes, currPeer.serialize()) if not synchronized: Sync.synchronize(currPeer.host) Sync.addr(currPeer.host)
class Peers: db = Config.getValue("PEERS_DB") subDb = Config.getValue("PEERS_SUB_DB") peers = Storage(db, subDb) hostname = Network.getHostname() ipAddress = Network.getIpAddress() if Config.getBoolValue('PEERS_ENABLE_SEEDS'): with open(Config.getValue('SEEDS_DIR')) as seeds: hosts = json.load(seeds) for host in hosts: if host != hostname and host != ipAddress: hostBytes = DataType.serialize(host) if peers.get(hostBytes) == None: peer = Peer() peer.host = host peer.lastUpdate = DataType.asTime() peers.set(hostBytes, peer.serialize())
def start(key): TimeIt.timings[key] = DataType.asTime()
def stop(key): startTime = TimeIt.timings[key] TimeIt.timings[key] = DataType.asTime() - startTime
def verifyFutureTimestamp(self, block): if block.timestamp - DataType.asTime() > 7200: return False return True