当前位置: 首页>>代码示例>>Python>>正文


Python web3.HTTPProvider方法代码示例

本文整理汇总了Python中web3.HTTPProvider方法的典型用法代码示例。如果您正苦于以下问题:Python web3.HTTPProvider方法的具体用法?Python web3.HTTPProvider怎么用?Python web3.HTTPProvider使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在web3的用法示例。


在下文中一共展示了web3.HTTPProvider方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import web3 [as 别名]
# 或者: from web3 import HTTPProvider [as 别名]
def __init__(self):
		# Path setting
		self.Fpath = "/tmp"
		self.DbPath = "/tmp/.db"
		# Web3 setting
		self.web3 = Web3(HTTPProvider('http://localhost:8545'))
		# DB setting
		self.conn = sqlite3.connect(self.DbPath+"/FileSign.db")
		self.c = self.conn.cursor()
		self.c.execute("create table if not exists AccountEhash(account text, Ehash text, PRIMARY KEY(account))")
		self.conn.commit()
		self.c.execute("create table if not exists SendLog(account text, Thash text)")
		self.conn.commit()
		self.c.execute("create table if not exists SignFhash(SignHash text, Fhash text, PRIMARY KEY(SignHash))")
		self.conn.commit()
		try:
			self.c.execute("insert into AccountEhash values ('admin','"+str(self.web3.eth.coinbase)+"')")
			self.conn.commit()
		except:
			pass 
开发者ID:yenkuanlee,项目名称:IPDC,代码行数:22,代码来源:control.py

示例2: __init__

# 需要导入模块: import web3 [as 别名]
# 或者: from web3 import HTTPProvider [as 别名]
def __init__(self,
                     contract_address,
                     contract_abi_string,
                     ethereum_chain_id,
                     http_provider,
                     websocket_provider,
                     gas_price_gwei,
                     gas_limit,):

            self.abi_dict = json.loads(contract_abi_string)
            self.contract_address = utils.checksum_encode(contract_address)
            self.ethereum_chain_id = int(ethereum_chain_id)

            self.w3 = Web3(HTTPProvider(http_provider))
            # self.wsw3 = Web3(WebsocketProvider(websocket_provider))

            self.contract = self.w3.eth.contract(address=self.contract_address, abi=self.abi_dict)
            self.decimals = self.get_decimals()

            self.gas_price = self.w3.toWei(gas_price_gwei, 'gwei')
            self.gas_limit = gas_limit
            self.transaction_max_value = self.gas_price * self.gas_limit 
开发者ID:teamsempo,项目名称:SempoBlockchain,代码行数:24,代码来源:ethereum_processor.py

示例3: __init__

# 需要导入模块: import web3 [as 别名]
# 或者: from web3 import HTTPProvider [as 别名]
def __init__(self,
                 http_provider_uri='http://localhost:8545',
                 number_of_blocks: int = 200,
                 cache_timeout_seconds: int = 10 * 60,
                 constant_gas_increment: int = 1):  # Increase a little for fastest mining for API Calls

        self.http_provider_uri = http_provider_uri
        self.http_session = requests.session()
        self.number_of_blocks = number_of_blocks
        self.cache_timeout = cache_timeout_seconds
        self.constant_gas_increment = constant_gas_increment
        self.w3 = Web3(HTTPProvider(http_provider_uri))
        try:
            if self.w3.net.version != 1:
                self.w3.middleware_onion.inject(geth_poa_middleware, layer=0)
            # For tests using dummy connections (like IPC)
        except (ConnectionError, FileNotFoundError):
            self.w3.middleware_onion.inject(geth_poa_middleware, layer=0) 
开发者ID:gnosis,项目名称:safe-relay-service,代码行数:20,代码来源:gas_station.py

示例4: find_transaction_details_in_redeem_event

# 需要导入模块: import web3 [as 别名]
# 或者: from web3 import HTTPProvider [as 别名]
def find_transaction_details_in_redeem_event(self, recipient_address: str, secret_hash: str, block_number: int):
        # web3.gastracker.io node does not support filtering
        # etc-geth.0xinfra.com not is not stable so it is used only for filtering
        filterable_web3 = Web3(HTTPProvider('https://etc-geth.0xinfra.com/'))

        event_signature_hash = self.web3.sha3(text="RedeemSwap(address,bytes20,bytes32)").hex()
        filter_options = {
            'fromBlock': block_number,
            'address': self.contract_address,
            'topics': [
                event_signature_hash,
                '0x' + encode_single('address', recipient_address).hex(),
                '0x' + encode_single('bytes20', bytes.fromhex(secret_hash)).hex()
            ]
        }

        event_filter = filterable_web3.eth.filter(filter_options)

        for _ in range(ETH_FILTER_MAX_ATTEMPTS):
            events = event_filter.get_all_entries()
            if events:
                return {
                    'secret': events[0]['data'][2:],
                    'transaction_hash': events[0]['transactionHash'].hex()
                } 
开发者ID:Lamden,项目名称:clove,代码行数:27,代码来源:ethereum_classic.py

示例5: __init__

# 需要导入模块: import web3 [as 别名]
# 或者: from web3 import HTTPProvider [as 别名]
def __init__(self, *args, **kwargs):
        """Initializes the `web3` object.

        Args:
            rpc_provider (HTTPProvider): Valid `web3` HTTPProvider instance (optional)
        """
        rpc_provider = kwargs.pop('rpc_provider', None)
        if not rpc_provider:
            timeout = getattr(settings, "ETHEREUM_NODE_TIMEOUT", 10)

            uri = settings.ETHEREUM_NODE_URI
            rpc_provider = HTTPProvider(
                endpoint_uri=uri,
                request_kwargs={
                    "timeout": timeout
                }
            )

        self.web3 = Web3(rpc_provider)

        # If running in a network with PoA consensus, inject the middleware
        if getattr(settings, "ETHEREUM_GETH_POA", False):
            self.web3.middleware_onion.inject(geth_poa_middleware, layer=0)

        super(Web3Service, self).__init__() 
开发者ID:artemistomaras,项目名称:django-ethereum-events,代码行数:27,代码来源:web3_service.py

示例6: __init__

# 需要导入模块: import web3 [as 别名]
# 或者: from web3 import HTTPProvider [as 别名]
def __init__(self,host='localhost',port=5001,mainnet=False):
		self.last_contract_address = None
		self.last_hash_added = None
		#self.api = ipfsapi.connect(host='127.0.0.1',port=port)
		# self.web3 = Web3(HTTPProvider('http://localhost:8545'))
		if mainnet:
			ipc_path=os.path.dirname(os.path.realpath(__file__))+'/data_mainnet/geth.ipc'
		else:
			ipc_path = os.path.dirname(os.path.realpath(__file__))+'/data/geth.ipc'
		print("IPCProvider path: ",ipc_path)
		self.web3 = Web3(IPCProvider(ipc_path))
		self.blockNumber = self.web3.eth.blockNumber
		self.eth_accounts = self.web3.personal.listAccounts
		self.account_index = 0
		self.ethereum_acc_pass = None
		
		self.tx = {}

		print("Initializing a DDASH Interface object.")

		# log Ethereum accounts to ddash/nfo/
		self.write_ethereum_address(mainnet)

	# contract_name is without the sol extension 
开发者ID:osmode,项目名称:ddash,代码行数:26,代码来源:bcinterface.py

示例7: main

# 需要导入模块: import web3 [as 别名]
# 或者: from web3 import HTTPProvider [as 别名]
def main(rpc_url: URI, private_key: Path, token_address: ChecksumAddress, amount: int) -> None:
    web3 = Web3(HTTPProvider(rpc_url))
    privkey = get_private_key(private_key)
    assert privkey is not None
    owner = private_key_to_address(privkey)
    web3.middleware_onion.add(construct_sign_and_send_raw_middleware(privkey))
    token_code = web3.eth.getCode(token_address, "latest")
    assert token_code != HexBytes("")
    token_contract = ContractManager(contracts_precompiled_path()).get_contract(
        CONTRACT_CUSTOM_TOKEN
    )
    token_proxy = web3.eth.contract(address=token_address, abi=token_contract["abi"])
    tx_hash = token_proxy.functions.mint(amount).transact({"from": owner})
    print(f"Minting tokens for address {owner}")
    print(f"Transaction hash {encode_hex(tx_hash)}")
    balance = token_proxy.functions.balanceOf(owner).call()
    print(f"Balance of {owner}: {balance}") 
开发者ID:raiden-network,项目名称:raiden-contracts,代码行数:19,代码来源:mint_tokens.py

示例8: __init__

# 需要导入模块: import web3 [as 别名]
# 或者: from web3 import HTTPProvider [as 别名]
def __init__(self) -> None:
        super().__init__(HTTPProvider("null"))
        self.enable_unstable_package_management_api()
        self.provider = None
        self._mainnet_w3: Optional[_Web3] = None
        self._genesis_hash: Optional[str] = None
        self._chain_uri: Optional[str] = None
        self._custom_middleware: Set = set() 
开发者ID:eth-brownie,项目名称:brownie,代码行数:10,代码来源:web3.py

示例9: _mainnet

# 需要导入模块: import web3 [as 别名]
# 或者: from web3 import HTTPProvider [as 别名]
def _mainnet(self) -> _Web3:
        # a web3 instance connected to the mainnet
        if self.isConnected() and CONFIG.active_network["id"] == "mainnet":
            return self
        try:
            mainnet = CONFIG.networks["mainnet"]
        except KeyError:
            raise MainnetUndefined("No 'mainnet' network defined") from None
        if not self._mainnet_w3:
            uri = _expand_environment_vars(mainnet["host"])
            self._mainnet_w3 = _Web3(HTTPProvider(uri))
            self._mainnet_w3.enable_unstable_package_management_api()
        return self._mainnet_w3 
开发者ID:eth-brownie,项目名称:brownie,代码行数:15,代码来源:web3.py

示例10: AddPeer

# 需要导入模块: import web3 [as 别名]
# 或者: from web3 import HTTPProvider [as 别名]
def AddPeer(message):
	print("AddPeer : "+message)
	from web3 import Web3, HTTPProvider
	web3 = Web3(HTTPProvider('http://localhost:8545'))
	try:
		web3.admin.addPeer(message)
	except:
		print("Add Peer Fail!!!") 
开发者ID:yenkuanlee,项目名称:IPDC,代码行数:10,代码来源:Dmqtt.py

示例11: __init__

# 需要导入模块: import web3 [as 别名]
# 或者: from web3 import HTTPProvider [as 别名]
def __init__(self):

        self.web3 = Web3(HTTPProvider(self.web3_provider_address))

        # Method IDs for transaction building. Built on the fly for developer reference (keeping away from magics)
        self.initiate = self.method_id('initiate(uint256,bytes20,address,address,bool,uint256)')
        self.redeem = self.method_id('redeem(bytes32)')
        self.refund = self.method_id('refund(bytes20, address)') 
开发者ID:Lamden,项目名称:clove,代码行数:10,代码来源:base.py

示例12: get_provider_from_uri

# 需要导入模块: import web3 [as 别名]
# 或者: from web3 import HTTPProvider [as 别名]
def get_provider_from_uri(node_uri: str):
        if node_uri.startswith('http'):
            return HTTPProvider(node_uri)
        elif node_uri.startswith('ipc'):
            path = node_uri.replace('ipc://', '')
            return IPCProvider(ipc_path=path)
        elif node_uri.startswith('test'):
            return EthereumTesterProvider(EthereumTester())
        else:
            raise ValueError('%s uri is not supported. Must start by http, ipc, or test' % node_uri) 
开发者ID:gnosis,项目名称:django-eth-events,代码行数:12,代码来源:web3_service.py

示例13: slow_provider

# 需要导入模块: import web3 [as 别名]
# 或者: from web3 import HTTPProvider [as 别名]
def slow_provider(self):
        if isinstance(self.provider, HTTPProvider):
            return HTTPProvider(endpoint_uri=self.provider.endpoint_uri,
                                request_kwargs={'timeout': self.slow_provider_timeout})
        elif isinstance(self.provider, IPCProvider):
            return IPCProvider(ipc_path=self.provider.ipc_path, timeout=self.slow_provider_timeout)
        else:
            return self.provider 
开发者ID:gnosis,项目名称:django-eth-events,代码行数:10,代码来源:web3_service.py

示例14: get_node_uri

# 需要导入模块: import web3 [as 别名]
# 或者: from web3 import HTTPProvider [as 别名]
def get_node_uri(self) -> str:
        if isinstance(self.provider, HTTPProvider):
            return self.provider.endpoint_uri 
开发者ID:gnosis,项目名称:django-eth-events,代码行数:5,代码来源:web3_service.py

示例15: has_http_provider

# 需要导入模块: import web3 [as 别名]
# 或者: from web3 import HTTPProvider [as 别名]
def has_http_provider(self):
        return isinstance(self.main_provider, HTTPProvider) 
开发者ID:gnosis,项目名称:django-eth-events,代码行数:4,代码来源:web3_service.py


注:本文中的web3.HTTPProvider方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。