def init(self): if self.getIndexBlockByHash(self.CHAIN_HEAD_INDEX) == None: genesisBlockGasLimit = Config.getIntValue("GENESIS_BLOCK_GAS_LIMIT") genesisBlockGasUsed = Config.getIntValue("GENESIS_BLOCK_GAS_USED") genesisBlockGasPrice = Config.getIntValue("GENESIS_BLOCK_GAS_PRICE") genesisBlock = Block() genesisBlock.previousHash = Config.getBytesValue("GENESIS_BLOCK_PREVIOUS_HASH", False) genesisBlock.gasLimit = genesisBlockGasLimit genesisBlock.gasUsed = genesisBlockGasUsed genesisBlock.nonce = Config.getIntValue("GENESIS_BLOCK_NONCE") genesisBlock.bits = Config.getIntValue("GENESIS_BLOCK_DIFFICULTY_BITS", 16) genesisBlock.timestamp = Config.getIntValue("GENESIS_BLOCK_TIMESTAMP") transaction = Transaction(genesisBlockGasLimit, genesisBlockGasPrice) coinbaseData = [] coinbaseData.append(Config.getValue("GENESIS_BLOCK_COINBASE_DATA")) transaction.addCoinbaseInput(coinbaseData) genesisBlockRewards = Config.getDecimalValue("GENESIS_BLOCK_REWARDS") genesisBlockRewards = Units.toUnits(genesisBlockRewards) genesisBlockPublicAddress = Config.getValue("GENESIS_BLOCK_PUBLIC_ADDRESS") genesisBlockPublicAddress = Address.toAddressBytes(genesisBlockPublicAddress) genesisBlockScript = Script.verifySignature() transaction.addOutput(genesisBlockPublicAddress, genesisBlockScript, genesisBlockRewards) transaction.hash() genesisBlock.transactions.append(transaction) genesisBlock.merkleRoot = MerkleTree.getMerkleRoot(genesisBlock.transactions, False) genesisBlock.witnessRoot = MerkleTree.getMerkleRoot(genesisBlock.transactions, True) self.addBlock(genesisBlock)
def deserialize(self, payload): if self.validatePayload(payload): self.deserializePayload(payload) if self.validateParameters(): for contract in self.params: self.contracts.append(Address.toAddressBytes(contract)) if self.validate(): return True return False
def deserialize(self, payload): if self.validatePayload(payload): self.deserializePayload(payload) if self.validateParameters(): for sidechain in self.params: self.sidechains.append(Address.toAddressBytes(sidechain)) if self.validate(): return True return False
def deserialize(self, payload): if self.validatePayload(payload): self.deserializePayload(payload) keys = None if self.isMultiSig(): if self.isTxFromMultiSig(): keys = [ 'fromAddress', 'publicKeys', 'signatures', 'threshold', 'toAddress', 'value', 'gasLimit', 'gasPrice' ] else: keys = [ 'fromAddress', 'threshold', 'toAddress', 'value', 'gasLimit', 'gasPrice' ] else: keys = [ 'fromAddress', 'toAddress', 'value', 'gasLimit', 'gasPrice' ] if self.validateParameters(keys): self.fromAddress = Address.toAddressBytes( self.params['fromAddress']) if self.isMultiSig(): if self.isTxFromMultiSig(): self.publicKeys = [] _publicKeys = self.params['publicKeys'] for publicKey in _publicKeys: publicKey = DataType.fromHex(publicKey) self.publicKeys.append(publicKey) self.signatures = [] _signatures = self.params['signatures'] for signature in _signatures: signature = DataType.fromHex(signature) self.signatures.append(signature) self.threshold = self.params['threshold'] self.toAddress = Address.toAddressBytes( self.params['toAddress']) self.value = Units.toUnits(self.params['value']) self.gasLimit = self.params['gasLimit'] self.gasPrice = Units.toUnits(self.params['gasPrice']) if self.validate(): return True return False
def deserialize(self, payload): if self.validatePayload(payload): self.deserializePayload(payload) keys = ['address', 'enabled'] if self.validateParameters(keys): self.address = Address.toAddressBytes(self.params['address']) self.enabled = self.params['enabled'] if self.validate(): return True return False
def deserialize(self, payload): if self.validatePayload(payload): self.deserializePayload(payload) keys = [ 'fromAddress', 'script', 'parameters', 'value', 'gasLimit', 'gasPrice' ] if self.validateParameters(keys): self.fromAddress = Address.toAddressBytes( self.params['fromAddress']) if self.isDeploy(): self.script = DataType.fromHex(self.params['script']) else: self.script = Address.toAddressBytes(self.params['script']) self.parameters = self.params['parameters'] self.value = Units.toUnits(self.params['value']) self.gasLimit = self.params['gasLimit'] self.gasPrice = Units.toUnits(self.params['gasPrice']) if self.validate(): return True return False
def deserialize(self, payload): if self.validatePayload(payload): self.deserializePayload(payload) keys = None if self.isSignAtomicSwapTx(): keys = [] else: keys = ['fromAddress', 'threshold', 'toAddress', 'value', 'gasLimit', 'gasPrice'] if self.validateParameters(keys): if self.isSignAtomicSwapTx(): self.unsignedTx = self.params else: self.fromAddress = Address.toAddressBytes(self.params['fromAddress']) self.threshold = self.params['threshold'] self.toAddress = Address.toAddressBytes(self.params['toAddress']) self.value = Units.toUnits(self.params['value']) self.gasLimit = self.params['gasLimit'] self.gasPrice = Units.toUnits(self.params['gasPrice']) if self.validate(): return True return False
def deserialize(self, payload): if self.validatePayload(payload): self.deserializePayload(payload) if self.validateParameters(): if self.isMultiSig(): for publicKey in self.params: publicKey = DataType.fromHex(publicKey) self.publicKeys.append(publicKey) else: for addr in self.params: addr = Address.toAddressBytes(addr) self.address.append(addr) if self.validate(): return True return False
def initialize(self): self.code = self.output.script[1:] parameters = [] if self.deploy: parameters = [] if self.output.extraData == None else self.output.extraData else: if self.output.hasExtScript(): parameters.extend(self.input.witness[3:]) else: self.stack.extend(self.input.witness) methodHash = False if self.deploy else True for parameter in parameters: if not isinstance(parameter, bytes): try: if methodHash: parameter = DataType.fromHex(parameter) parameter = DataType.serialize(parameter) methodHash = False else: parameter = DataType.asInt(parameter) except ValueError: try: parameter = DataType.fromHex(parameter) parameter = DataType.serialize(parameter) except ValueError: parameter = Address.toAddressBytes(parameter) if self.deploy: self.code += DataType.zeroFillArray(parameter, 32) else: if len(self.data) == 0: self.data += parameter else: self.data += DataType.zeroFillArray(parameter, 32) if len(self.data) > 0 and len(self.data) < 32: fillLen = 32 - len(self.data) self.data.extend(fillLen * b'\x00')
def deserialize(self, buffer): self.address = Address.toAddressBytes(buffer['address'])
def deserialize(self, buffer): self.address = Address.toAddressBytes(buffer['address']) self.public = DataType.fromHex(buffer['public']) self.private = DataType.fromHex(buffer['private']) self.type = buffer['type']