コード例 #1
0
    def sign_transaction(self,
                         txn: TransactionAPI) -> Optional[TransactionAPI]:
        if self.locked and not click.confirm(f"{txn}\n\nSign: "):
            return None

        signed_txn = EthAccount.sign_transaction(txn.as_dict(), self.__key)

        txn.signature = (signed_txn.v.to_bytes(1, "big") +
                         signed_txn.r.to_bytes(32, "big") +
                         signed_txn.s.to_bytes(32, "big"))

        return txn
コード例 #2
0
ファイル: accounts.py プロジェクト: fubuloubu/ape
 def sign_transaction(
         self, txn: TransactionAPI) -> Optional[TransactionSignature]:
     signed_txn = EthAccount.sign_transaction(txn.dict(), self.private_key)
     return TransactionSignature(  # type: ignore
         v=signed_txn.v,
         r=to_bytes(signed_txn.r),
         s=to_bytes(signed_txn.s),
     )
コード例 #3
0
 def estimate_gas_cost(self, txn: TransactionAPI) -> int:
     try:
         result = self.web3.eth.estimate_gas(txn.dict())  # type: ignore
         return result
     except ValidationError as err:
         message = gas_estimation_error_message(err)
         raise TransactionError(base_err=err, message=message) from err
     except TransactionFailed as err:
         raise self.get_virtual_machine_error(err) from err
コード例 #4
0
    def send_call(self, txn: TransactionAPI) -> bytes:
        data = txn.dict(exclude_none=True)
        if "gas" not in data or data["gas"] == 0:
            data["gas"] = int(1e12)

        try:
            return self.web3.eth.call(data)
        except ValidationError as err:
            raise VirtualMachineError(base_err=err) from err
        except TransactionFailed as err:
            raise self.get_virtual_machine_error(err) from err
コード例 #5
0
    def sign_transaction(
            self, txn: TransactionAPI) -> Optional[TransactionSignature]:
        user_approves = self.__autosign or click.confirm(f"{txn}\n\nSign: ")
        if not user_approves:
            return None

        signed_txn = EthAccount.sign_transaction(
            txn.dict(exclude_none=True, by_alias=True), self.__key)
        return TransactionSignature(  # type: ignore
            v=signed_txn.v,
            r=to_bytes(signed_txn.r),
            s=to_bytes(signed_txn.s),
        )
コード例 #6
0
    def send_transaction(self, txn: TransactionAPI) -> ReceiptAPI:
        try:
            txn_hash = self.web3.eth.send_raw_transaction(txn.serialize_transaction())
        except ValidationError as err:
            raise VirtualMachineError(base_err=err) from err
        except TransactionFailed as err:
            raise self.get_virtual_machine_error(err) from err

        receipt = self.get_transaction(
            txn_hash.hex(), required_confirmations=txn.required_confirmations or 0
        )
        if txn.gas_limit is not None and receipt.ran_out_of_gas:
            raise OutOfGasError()

        self._try_track_receipt(receipt)
        return receipt
コード例 #7
0
 def send_transaction(self, txn: TransactionAPI) -> ReceiptAPI:
     txn_hash = self._web3.eth.send_raw_transaction(txn.encode())
     return self.get_transaction(txn_hash.hex())
コード例 #8
0
 def send_call(self, txn: TransactionAPI) -> bytes:
     data = txn.as_dict()
     if data["gas"] == 0:
         data["gas"] = int(1e12)
     return self._web3.eth.call(data)
コード例 #9
0
 def estimate_gas_cost(self, txn: TransactionAPI) -> int:
     return self._web3.eth.estimate_gas(txn.as_dict())  # type: ignore
コード例 #10
0
 def serialize_transaction(self, transaction: TransactionAPI) -> bytes:
     return transaction.serialize_transaction()
コード例 #11
0
ファイル: providers.py プロジェクト: moshemalawach/ape
 def send_call(self, txn: TransactionAPI) -> bytes:
     data = txn.encode()
     return self._web3.eth.call(data)