mirror of
https://github.com/FlipsideCrypto/web3.py.git
synced 2026-02-06 10:56:47 +00:00
basic docs updates and remove usage from othe parts of code
This commit is contained in:
parent
e300e64d83
commit
ce23481cd6
@ -8,7 +8,7 @@ Contracts
|
||||
Contract Factories
|
||||
------------------
|
||||
|
||||
.. py:class:: Contract(abi, address=None, code=None, code_runtime=None, source=None)
|
||||
.. py:class:: Contract(address)
|
||||
|
||||
The ``Contract`` class is not intended to be used or instantiated directly.
|
||||
Instead you should use the ``web3.eth.contract(...)`` method to generate
|
||||
@ -35,19 +35,19 @@ Each Contract Factory exposes the following properties.
|
||||
The contract ABI array.
|
||||
|
||||
|
||||
.. py:attribute:: Contract.code
|
||||
.. py:attribute:: Contract.bytecode
|
||||
|
||||
The contract bytecode string. May be ``None`` if not provided during
|
||||
factory creation.
|
||||
|
||||
|
||||
.. py:attribute:: Contract.code_runtime
|
||||
.. py:attribute:: Contract.bytecode_runtime
|
||||
|
||||
The runtime part of the contract bytecode string. May be ``None`` if not
|
||||
provided during factory creation.
|
||||
|
||||
|
||||
.. py:attribute:: Contract.code_runtime
|
||||
.. py:attribute:: Contract.bytecode_runtime
|
||||
|
||||
The runtime part of the contract bytecode string. May be ``None`` if not
|
||||
provided during factory creation.
|
||||
|
||||
@ -579,22 +579,31 @@ with the filtering API.
|
||||
Contracts
|
||||
---------
|
||||
|
||||
.. py:method:: Eth.contract(abi, address=None, code=None, code_runtime=None, source=None)
|
||||
.. py:method:: Eth.contract(address=None, contract_name=None, ContractFactoryClass=Contract, **contract_factory_kwargs)
|
||||
|
||||
If ``address`` is provided then this method will return an instance of the
|
||||
contract defined by ``abi``.
|
||||
contract defined by ``abi``. Otherwise the newly created contract class
|
||||
will be returned.
|
||||
|
||||
If ``address`` is ``None`` then this method will return a Contract Factory,
|
||||
which can be though of as the python class that represents your contract.
|
||||
``contract_name`` will be used as the name of the contract class. If
|
||||
``None`` then the name of the ``ContractFactoryClass`` will be used.
|
||||
|
||||
The ``abi`` parameter should be an array containing the ABI definition of
|
||||
the contract functions and events.
|
||||
``ContractFactoryClass`` will be used as the base Contract class.
|
||||
|
||||
The ``code`` parameter should be the full contract bytecode.
|
||||
The following arguments are accepted for contract class creation.
|
||||
|
||||
The ``code_runtime`` parameter should be the runtime part of the contract bytecode.
|
||||
|
||||
The ``source`` parameter should be a string containing the full source code
|
||||
of the contract.
|
||||
- ``abi``
|
||||
- ``asm``
|
||||
- ``ast``
|
||||
- ``bytecode``
|
||||
- ``bytecode_runtime``
|
||||
- ``clone_bin``
|
||||
- ``dev_doc``
|
||||
- ``interface``
|
||||
- ``metadata``
|
||||
- ``opcodes``
|
||||
- ``src_map``
|
||||
- ``src_map_runtime``
|
||||
- ``user_doc``
|
||||
|
||||
See :doc:`./contracts` for more information about how to use contracts.
|
||||
|
||||
@ -74,8 +74,8 @@ def MATH_ABI():
|
||||
def MathContract(web3, MATH_ABI, MATH_CODE, MATH_RUNTIME, MATH_SOURCE):
|
||||
return web3.eth.contract(
|
||||
abi=MATH_ABI,
|
||||
code=MATH_CODE,
|
||||
code_runtime=MATH_RUNTIME,
|
||||
bytecode=MATH_CODE,
|
||||
bytecode_runtime=MATH_RUNTIME,
|
||||
source=MATH_SOURCE,
|
||||
)
|
||||
|
||||
@ -114,8 +114,8 @@ def SimpleConstructorContract(web3,
|
||||
SIMPLE_CONSTRUCTOR_ABI):
|
||||
return web3.eth.contract(
|
||||
abi=SIMPLE_CONSTRUCTOR_ABI,
|
||||
code=SIMPLE_CONSTRUCTOR_CODE,
|
||||
code_runtime=SIMPLE_CONSTRUCTOR_RUNTIME,
|
||||
bytecode=SIMPLE_CONSTRUCTOR_CODE,
|
||||
bytecode_runtime=SIMPLE_CONSTRUCTOR_RUNTIME,
|
||||
source=SIMPLE_CONSTRUCTOR_SOURCE,
|
||||
)
|
||||
|
||||
@ -155,8 +155,8 @@ def WithConstructorArgumentsContract(web3,
|
||||
WITH_CONSTRUCTOR_ARGUMENTS_ABI):
|
||||
return web3.eth.contract(
|
||||
abi=WITH_CONSTRUCTOR_ARGUMENTS_ABI,
|
||||
code=WITH_CONSTRUCTOR_ARGUMENTS_CODE,
|
||||
code_runtime=WITH_CONSTRUCTOR_ARGUMENTS_RUNTIME,
|
||||
bytecode=WITH_CONSTRUCTOR_ARGUMENTS_CODE,
|
||||
bytecode_runtime=WITH_CONSTRUCTOR_ARGUMENTS_RUNTIME,
|
||||
source=WITH_CONSTRUCTOR_ARGUMENTS_SOURCE,
|
||||
)
|
||||
|
||||
@ -195,8 +195,8 @@ def WithConstructorAddressArgumentsContract(web3,
|
||||
WITH_CONSTRUCTOR_ADDRESS_ABI):
|
||||
return web3.eth.contract(
|
||||
abi=WITH_CONSTRUCTOR_ADDRESS_ABI,
|
||||
code=WITH_CONSTRUCTOR_ADDRESS_CODE,
|
||||
code_runtime=WITH_CONSTRUCTOR_ADDRESS_RUNTIME,
|
||||
bytecode=WITH_CONSTRUCTOR_ADDRESS_CODE,
|
||||
bytecode_runtime=WITH_CONSTRUCTOR_ADDRESS_RUNTIME,
|
||||
source=WITH_CONSTRUCTOR_ADDRESS_SOURCE,
|
||||
)
|
||||
|
||||
@ -255,8 +255,8 @@ def STRING_ABI():
|
||||
@pytest.fixture()
|
||||
def STRING_CONTRACT(STRING_SOURCE, STRING_CODE, STRING_RUNTIME, STRING_ABI):
|
||||
return {
|
||||
'code': STRING_CODE,
|
||||
'code_runtime': STRING_RUNTIME,
|
||||
'bytecode': STRING_CODE,
|
||||
'bytecode_runtime': STRING_RUNTIME,
|
||||
'abi': STRING_ABI,
|
||||
'source': STRING_SOURCE,
|
||||
}
|
||||
@ -382,8 +382,8 @@ def EMITTER(EMITTER_CODE,
|
||||
EMITTER_ABI,
|
||||
EMITTER_SOURCE):
|
||||
return {
|
||||
'code': EMITTER_CODE,
|
||||
'code_runtime': EMITTER_RUNTIME,
|
||||
'bytecode': EMITTER_CODE,
|
||||
'bytecode_runtime': EMITTER_RUNTIME,
|
||||
'source': EMITTER_SOURCE,
|
||||
'abi': EMITTER_ABI,
|
||||
}
|
||||
@ -404,8 +404,8 @@ def emitter(web3_empty, Emitter, wait_for_transaction, wait_for_block):
|
||||
deploy_receipt = wait_for_transaction(web3, deploy_txn_hash)
|
||||
contract_address = deploy_receipt['contractAddress']
|
||||
|
||||
code = web3.eth.getCode(contract_address)
|
||||
assert code == Emitter.code_runtime
|
||||
bytecode = web3.eth.getCode(contract_address)
|
||||
assert bytecode == Emitter.bytecode_runtime
|
||||
return Emitter(address=contract_address)
|
||||
|
||||
|
||||
|
||||
@ -7,14 +7,14 @@ def test_class_construction_sets_class_vars(web3, MATH_ABI, MATH_CODE,
|
||||
MATH_RUNTIME, MATH_SOURCE):
|
||||
MathContract = web3.eth.contract(
|
||||
abi=MATH_ABI,
|
||||
code=MATH_CODE,
|
||||
code_runtime=MATH_RUNTIME,
|
||||
bytecode=MATH_CODE,
|
||||
bytecode_runtime=MATH_RUNTIME,
|
||||
source=MATH_SOURCE,
|
||||
)
|
||||
|
||||
assert MathContract.web3 == web3
|
||||
assert MathContract.code == MATH_CODE
|
||||
assert MathContract.code_runtime == MATH_RUNTIME
|
||||
assert MathContract.bytecode == MATH_CODE
|
||||
assert MathContract.bytecode_runtime == MATH_RUNTIME
|
||||
assert MathContract.source == MATH_SOURCE
|
||||
|
||||
|
||||
|
||||
@ -15,8 +15,8 @@ def math_contract(web3, MATH_ABI, MATH_CODE, MATH_RUNTIME, MATH_SOURCE,
|
||||
wait_for_transaction):
|
||||
MathContract = web3.eth.contract(
|
||||
abi=MATH_ABI,
|
||||
code=MATH_CODE,
|
||||
code_runtime=MATH_RUNTIME,
|
||||
bytecode=MATH_CODE,
|
||||
bytecode_runtime=MATH_RUNTIME,
|
||||
source=MATH_SOURCE,
|
||||
)
|
||||
deploy_txn = MathContract.deploy({'from': web3.eth.coinbase})
|
||||
|
||||
@ -23,8 +23,8 @@ def emitter(web3, Emitter, wait_for_transaction, wait_for_block):
|
||||
deploy_receipt = wait_for_transaction(web3, deploy_txn_hash)
|
||||
contract_address = deploy_receipt['contractAddress']
|
||||
|
||||
code = web3.eth.getCode(contract_address)
|
||||
assert code == Emitter.code_runtime
|
||||
bytecode = web3.eth.getCode(contract_address)
|
||||
assert bytecode == Emitter.bytecode_runtime
|
||||
return Emitter(address=contract_address)
|
||||
|
||||
|
||||
|
||||
@ -29,15 +29,19 @@ class ContactClassForTest(Contract):
|
||||
((ABI,), {}, {'abi': ABI}),
|
||||
((ABI,), {'abi': ABI}, TypeError),
|
||||
((ABI, ADDRESS), {}, {'abi': ABI, 'address': ADDRESS}),
|
||||
(
|
||||
(ABI, ADDRESS),
|
||||
{'code': '0x1', 'code_runtime': '0x2'},
|
||||
{'abi': ABI, 'address': ADDRESS, 'bytecode': '0x1', 'bytecode_runtime': '0x2'}),
|
||||
(
|
||||
(ABI, ADDRESS, '0x1', '0x2', '0x3'),
|
||||
{},
|
||||
{'abi': ABI, 'address': ADDRESS, 'binary': '0x1', 'binary_runtime': '0x2', 'source': '0x3'},
|
||||
{'abi': ABI, 'address': ADDRESS, 'bytecode': '0x1', 'bytecode_runtime': '0x2', 'source': '0x3'},
|
||||
),
|
||||
(
|
||||
tuple(),
|
||||
{'abi': ABI, 'address': ADDRESS, 'code': '0x1', 'code_runtime': '0x2', 'source': '0x3'},
|
||||
{'abi': ABI, 'address': ADDRESS, 'binary': '0x1', 'binary_runtime': '0x2', 'source': '0x3'},
|
||||
{'abi': ABI, 'address': ADDRESS, 'bytecode': '0x1', 'bytecode_runtime': '0x2', 'source': '0x3'},
|
||||
),
|
||||
((ABI, ADDRESS), {'abi': ABI}, TypeError),
|
||||
((ABI, ADDRESS), {'address': ADDRESS}, TypeError),
|
||||
|
||||
@ -15,8 +15,8 @@ def math_contract(web3, MATH_ABI, MATH_CODE, MATH_RUNTIME, MATH_SOURCE,
|
||||
wait_for_transaction):
|
||||
MathContract = web3.eth.contract(
|
||||
abi=MATH_ABI,
|
||||
code=MATH_CODE,
|
||||
code_runtime=MATH_RUNTIME,
|
||||
bytecode=MATH_CODE,
|
||||
bytecode_runtime=MATH_RUNTIME,
|
||||
source=MATH_SOURCE,
|
||||
)
|
||||
deploy_txn = MathContract.deploy({'from': web3.eth.coinbase})
|
||||
|
||||
@ -123,8 +123,8 @@ def EMITTER(EMITTER_CODE,
|
||||
EMITTER_ABI,
|
||||
EMITTER_SOURCE):
|
||||
return {
|
||||
'code': EMITTER_CODE,
|
||||
'code_runtime': EMITTER_RUNTIME,
|
||||
'bytecode': EMITTER_CODE,
|
||||
'bytecode_runtime': EMITTER_RUNTIME,
|
||||
'source': EMITTER_SOURCE,
|
||||
'abi': EMITTER_ABI,
|
||||
}
|
||||
@ -142,8 +142,8 @@ def emitter(web3, Emitter, wait_for_transaction, wait_for_block):
|
||||
deploy_receipt = wait_for_transaction(web3, deploy_txn_hash)
|
||||
contract_address = deploy_receipt['contractAddress']
|
||||
|
||||
code = web3.eth.getCode(contract_address)
|
||||
assert code == Emitter.code_runtime
|
||||
bytecode = web3.eth.getCode(contract_address)
|
||||
assert bytecode == Emitter.bytecode_runtime
|
||||
return Emitter(address=contract_address)
|
||||
|
||||
|
||||
|
||||
@ -107,8 +107,8 @@ class Contract(object):
|
||||
asm = None
|
||||
ast = None
|
||||
|
||||
binary = None
|
||||
binary_runtime = None
|
||||
bytecode = None
|
||||
bytecode_runtime = None
|
||||
clone_bin = None
|
||||
|
||||
dev_doc = None
|
||||
@ -129,10 +129,6 @@ class Contract(object):
|
||||
"""Create a new smart contract proxy object.
|
||||
|
||||
:param address: Contract address as 0x hex string
|
||||
:param abi: Override class level definition
|
||||
:param code: Override class level definition
|
||||
:param code_runtime: Override class level definition
|
||||
:param source: Override class level definition
|
||||
"""
|
||||
if self.web3 is None:
|
||||
raise AttributeError(
|
||||
@ -185,9 +181,9 @@ class Contract(object):
|
||||
if abi is not empty:
|
||||
self.abi = abi
|
||||
if code is not empty:
|
||||
self.binary = code
|
||||
self.bytecode = code
|
||||
if code_runtime is not empty:
|
||||
self.binary_runtime = code_runtime
|
||||
self.bytecode_runtime = code_runtime
|
||||
if source is not empty:
|
||||
self._source = source
|
||||
|
||||
@ -224,22 +220,22 @@ class Contract(object):
|
||||
def code(self):
|
||||
warnings.warn(DeprecationWarning(
|
||||
"The `code` property has been deprecated. You should update your "
|
||||
"code to access this value through `contract.binary`. The `code` "
|
||||
"code to access this value through `contract.bytecode`. The `code` "
|
||||
"property will be removed in future releases"
|
||||
))
|
||||
if self.binary is not None:
|
||||
return self.binary
|
||||
if self.bytecode is not None:
|
||||
return self.bytecode
|
||||
raise AttributeError("No contract code was specified for thes contract")
|
||||
|
||||
@property
|
||||
def code_runtime(self):
|
||||
warnings.warn(DeprecationWarning(
|
||||
"The `code_runtime` property has been deprecated. You should update your "
|
||||
"code to access this value through `contract.binary_runtime`. The `code_runtime` "
|
||||
"code to access this value through `contract.bytecode_runtime`. The `code_runtime` "
|
||||
"property will be removed in future releases"
|
||||
))
|
||||
if self.binary_runtime is not None:
|
||||
return self.binary_runtime
|
||||
if self.bytecode_runtime is not None:
|
||||
return self.bytecode_runtime
|
||||
raise AttributeError("No contract code_runtime was specified for thes contract")
|
||||
|
||||
@property
|
||||
@ -287,9 +283,9 @@ class Contract(object):
|
||||
else:
|
||||
deploy_transaction = dict(**transaction)
|
||||
|
||||
if not cls.code:
|
||||
if not cls.bytecode:
|
||||
raise ValueError(
|
||||
"Cannot deploy a contract that does not have 'code' associated "
|
||||
"Cannot deploy a contract that does not have 'bytecode' associated "
|
||||
"with it"
|
||||
)
|
||||
|
||||
@ -740,10 +736,10 @@ class Contract(object):
|
||||
arguments = merge_args_and_kwargs(constructor_abi, args, kwargs)
|
||||
|
||||
deploy_data = add_0x_prefix(
|
||||
cls._encode_abi(constructor_abi, arguments, data=cls.code)
|
||||
cls._encode_abi(constructor_abi, arguments, data=cls.bytecode)
|
||||
)
|
||||
else:
|
||||
deploy_data = add_0x_prefix(cls.code)
|
||||
deploy_data = add_0x_prefix(cls.bytecode)
|
||||
|
||||
return deploy_data
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user