Exemple #1
0
    def handleLocalScript(self, fromAccount, output, deploy):
        gasLimit = Config.getIntValue('TRANSACTION_LOCAL_GAS_LIMIT')
        gasPrice = Config.getIntValue('TRANSACTION_LOCAL_GAS_PRICE')
        localTx = Transaction(gasLimit, gasPrice)
        localTx.gasRemaining = Config.getIntValue(
            'TRANSACTION_LOCAL_GAS_REMAINING')
        _input = None
        if deploy:
            pass
        else:
            scriptData = []
            scriptData.append(DataType.zeroFillArray(0, 32))
            scriptData.append(DataType.zeroFillArray(0, 32))
            scriptData.append(fromAccount.address)
            scriptData.extend(self.parameters)

            _input = Input(Config.getValue('SCRIPT_TRANSACTION_ID'),
                           Config.getIntValue('SCRIPT_OUTPUT_INDEX'))
            _input.witness = scriptData
        if RVM.run(localTx, _input, output, True, deploy, True):
            if len(localTx.internalOutputs) > 0:
                internalOutput = localTx.internalOutputs[-1]
                if deploy:
                    PersistentStorage.add(internalOutput.address,
                                          internalOutput, True)
                    result = 'Script Deployed Locally'
                else:
                    result = internalOutput.script
                    try:
                        result = DataType.toHex(result)
                        result = DataType.asInt(result, 16)
                    except ValueError:
                        pass
                return result
        return None
Exemple #2
0
 def sload(self):
     PersistentStorage.dump()
     key = self.pop()
     key = self.persistentStorageKey + key
     value = PersistentStorage.get(key, True)
     if value == None:
         value = DataType.zeroFillArray(0, 32)
     self.stack.append(value)
Exemple #3
0
 def callvalue(self):
     value = 0
     if self.deploy: 
         value = self.output.value
     else:
         contractAddress = self.output.address
         for txOut in self.transaction.outputs:
             if txOut.address == contractAddress:
                 value += txOut.value
     value = DataType.zeroFillArray(value, 32)
     self.stack.append(value)
Exemple #4
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')
Exemple #5
0
 def gas(self):
     gasRemaining = self.gasRemaining
     gasRemaining = DataType.zeroFillArray(gasRemaining, 32)
     self.stack.append(gasRemaining)
Exemple #6
0
 def mstore(self):
     offset = self.popAsInt()
     value = self.pop()
     self.expandMemory(offset, 32)
     self.memory[offset:offset + 32] = DataType.zeroFillArray(value, 32)
     print('memory', 'mstore', value, len(self.memory))
Exemple #7
0
 def gaslimit(self):
     gasLimit = self.chainHeadBlock.gasLimit
     gasLimit = DataType.zeroFillArray(gasLimit, 32)
     self.stack.append(gasLimit)
Exemple #8
0
 def gasprice(self):
     gasPrice = self.transaction.gasPrice
     gasPrice = DataType.zeroFillArray(gasPrice, 32)
     self.stack.append(gasPrice)