Ejemplo n.º 1
0
    async def execute_script(
        self,
        script: Script,
        at_block_id: Optional[bytes] = None,
        at_block_height: Optional[int] = None,
    ) -> Optional[Value]:
        s = script.code.encode("utf-8")
        a = encode_arguments(script.arguments)

        if at_block_id is not None:
            log.debug(f"Executing script at block id {at_block_id.hex()}")
            result = await self.execute_script_at_block_i_d(
                script=s, arguments=a, block_id=at_block_id)
        elif at_block_height is not None:
            log.debug(f"Executing script at block height {at_block_height}")
            result = await self.execute_script_at_block_height(
                script=s, arguments=a, block_height=at_block_height)
        else:
            log.debug(f"Executing script at latest block", )
            result = await self.execute_script_at_latest_block(script=s,
                                                               arguments=a)

        log.debug(f"Script Executed")

        if result is None or result.value is None:
            return None
        cadence_value = json.loads(result.value,
                                   object_hook=cadence_object_hook)
        return cadence_value
Ejemplo n.º 2
0
 def _payload_form(self):
     return [
         self.code.encode("utf-8"),
         encode_arguments(self.arguments),
         self.reference_block_id,
         rlp_encode_uint64(self.gas_limit),
         self.proposal_key.key_address.bytes,
         rlp_encode_uint64(self.proposal_key.key_id),
         rlp_encode_uint64(self.proposal_key.key_sequence_number),
         self.payer.bytes,
         [a.bytes for a in self.authorizers],
     ]
Ejemplo n.º 3
0
    def to_grpc(self) -> entities.Transaction:
        tx = entities.Transaction()
        tx.script = self.code.encode("utf-8")
        tx.arguments = encode_arguments(self.arguments)
        tx.reference_block_id = self.reference_block_id
        tx.gas_limit = self.gas_limit
        tx.payer = self.payer.bytes
        tx.authorizers = [a.bytes for a in self.authorizers]

        proposal_key = entities.TransactionProposalKey()
        proposal_key.address = self.proposal_key.key_address.bytes
        proposal_key.key_id = self.proposal_key.key_id
        proposal_key.sequence_number = self.proposal_key.key_sequence_number

        tx.proposal_key = proposal_key
        tx.payload_signatures = [s.rpc_form() for s in self.payload_signatures]
        tx.envelope_signatures = [s.rpc_form() for s in self.envelope_signatures]

        return tx