Beispiel #1
0
 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
Beispiel #2
0
 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, 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
Beispiel #4
0
 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 getBytesValue(key, hexStr=True):
    if hexStr:
        return DataType.fromHex(Config.config[key])
    else:
        return DataType.serialize(Config.config[key])
 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']