Skip to content

Commit a6281ea

Browse files
committed
add docs
1 parent a8eb473 commit a6281ea

File tree

1 file changed

+85
-2
lines changed

1 file changed

+85
-2
lines changed

convex_api/contract.py

+85-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,32 @@
1010

1111
class Contract:
1212
def __init__(self, convex):
13+
"""
14+
15+
Contract class to provide access and name resolution to deployed convex contracts.
16+
17+
"""
1318
self._convex = convex
1419
self._name = None
1520
self._address = None
1621
self._owner_address = None
1722

1823
def load(self, name=None, address=None, owner_address=None):
24+
"""
25+
26+
Load a contract details using it's registered name or directly using it's known address.
27+
28+
:param str name: Name of the contract that has been registered.
29+
If provided the address and owner_address of the registration is stored within this object
30+
31+
:param str, int, Account address: Address of the contract, if the name is not known,
32+
then you can provide the actual address of the contract.
1933
34+
:param str, int, Account owner_address: If the contract is registered the owner address of the resgistration.
35+
36+
:returns int The address of the resolved contract
37+
38+
"""
2039
if name:
2140
address = self.resolve_address(name)
2241
owner_address = self.resolve_owner_address(name)
@@ -28,11 +47,29 @@ def load(self, name=None, address=None, owner_address=None):
2847
if owner_address is None:
2948
owner_address = address
3049

31-
self._address = address
32-
self._owner_address = owner_address
50+
self._address = to_address(address)
51+
self._owner_address = to_address(owner_address)
3352
return self._address
3453

3554
def deploy(self, account, text=None, filename=None, name=None, owner_account=None):
55+
"""
56+
57+
Deploy a new/updated contract on the convex network.
58+
59+
:param Account account: Account to use to deploy the contract
60+
61+
:param str text: Contract text to deploy
62+
63+
:param str filename: Filename of the contract to deploy
64+
65+
:param str name: Name of the contract to register
66+
67+
:param Account onwer_account: Optional owner account of the registration.
68+
If not provided then the Account will be used.
69+
70+
:returns Address of the new contract
71+
72+
"""
3673
if filename:
3774
with open(filename, 'r') as fp:
3875
text = fp.read()
@@ -57,14 +94,50 @@ def deploy(self, account, text=None, filename=None, name=None, owner_account=Non
5794
return address
5895

5996
def register(self, name, address, account):
97+
"""
98+
99+
Register a contract address with a resolvable name. This name can be used on the Convex network to resolve
100+
to the address.
101+
102+
:param str name: Name to register.
103+
104+
:param str, int, Account address: Address to use to assign with the name.
105+
106+
:param Account account: Account who owns the registration.
107+
108+
:returns Result from the register transaction
109+
110+
"""
60111
return self._convex.registry.register(name, address, account)
61112

62113
def send(self, transaction, account):
114+
"""
115+
116+
Sends a contract transaction to the contract. You need to run `load` before calling this method.
117+
118+
:param str transaction: Transaction to send to the contract.
119+
120+
:param Account account: Account to pay for the transaction.
121+
122+
:returns The transaction result.
123+
124+
"""
63125
if not self._address:
64126
raise ValueError(f'No contract address found for {self._name}')
65127
return self._convex.send(f'(call #{self._address} {transaction})', account)
66128

67129
def query(self, transaction, account_address=None):
130+
"""
131+
132+
Sends a query to the contract.
133+
134+
:param str transaction: The transaction query to send to the contract
135+
136+
:param str, int, Account account_address: The address to provide as the sender for this query.
137+
138+
:returns The query result
139+
140+
"""
68141
if not self._address:
69142
raise ValueError(f'No contract address found for {self._name}')
70143
if account_address is None:
@@ -74,9 +147,19 @@ def query(self, transaction, account_address=None):
74147
return self._convex.query(f'(call #{self._address} {transaction})', account_address)
75148

76149
def resolve_address(self, name):
150+
"""
151+
152+
Return an address from a registered name.
153+
154+
"""
77155
return self._convex.registry.resolve_address(name)
78156

79157
def resolve_owner_address(self, name):
158+
"""
159+
160+
Returns the register owner of a registered name.
161+
162+
"""
80163
return self._convex.registry.resolve_owner(name)
81164

82165
@property

0 commit comments

Comments
 (0)