def sign_and_send_raw_middleware(make_request, w3): format_and_fill_tx = compose( format_transaction, fill_transaction_defaults(w3), fill_nonce(w3)) def middleware(method, params): if method != "eth_sendTransaction": return make_request(method, params) else: transaction = format_and_fill_tx(params[0]) if 'from' not in transaction: return make_request(method, params) elif transaction.get('from') not in accounts: return make_request(method, params) account = accounts[transaction['from']] raw_tx = account.signTransaction(transaction).rawTransaction.hex() return make_request( "eth_sendRawTransaction", [raw_tx]) return middleware
def sign_and_send_raw_middleware( make_request: Callable[[RPCEndpoint, Any], Any], w3: "Web3") -> Callable[[RPCEndpoint, Any], RPCResponse]: format_and_fill_tx = compose(format_transaction, fill_transaction_defaults(w3), fill_nonce(w3)) def middleware(method: RPCEndpoint, params: Any) -> RPCResponse: if method != "eth_sendTransaction": return make_request(method, params) else: transaction = format_and_fill_tx(params[0]) if 'from' not in transaction: return make_request(method, params) elif transaction.get('from') not in accounts: return make_request(method, params) account = accounts[transaction['from']] raw_tx = account.sign_transaction(transaction).rawTransaction return make_request(RPCEndpoint("eth_sendRawTransaction"), [raw_tx]) return middleware
def sign_and_send_raw_middleware(make_request, w3): format_and_fill_tx = compose( format_transaction, fill_transaction_defaults(w3), fill_nonce(w3)) def middleware(method, params): if method != "eth_sendTransaction": return make_request(method, params) else: transaction = format_and_fill_tx(params[0]) if 'from' not in transaction: return make_request(method, params) elif transaction.get('from') not in accounts: return make_request(method, params) account = accounts[transaction['from']] raw_tx = account.signTransaction(transaction).rawTransaction return make_request( "eth_sendRawTransaction", [raw_tx]) return middleware
def _build_and_sign_transaction(function_call, *, web3, transaction_options, private_key): account = Account.privateKeyToAccount(private_key) if "from" in transaction_options and transaction_options[ "from"] != account.address: raise ValueError( "From can not be set in transaction_options if a private key is used" ) transaction_options["from"] = account.address transaction = fill_nonce( web3, function_call.buildTransaction(transaction_options)) return account.signTransaction(transaction)