Skip to content

Commit 6d497b2

Browse files
committed
rename ConvexAPI to API
1 parent a97270b commit 6d497b2

17 files changed

+75
-1116
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Change log
22

3+
### 0.2.0
4+
+ Add KeyPair class, now you have to pass a KeyPair object to the `create_account` method.
5+
+ Rename ConvexAPI to API
6+
37
### 0.1.4
48
+ Add address '#' identifier before each address number.
59

README.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,43 @@ First you need to download the Convex-API-py package from the python package ind
1212

1313
You can now access the convex network, and get a balance from an existing account on the network by doing the following:
1414

15-
>>> from convex_api import ConvexAPI
16-
>>> convex_api = ConvexAPI('https://convex.world')
17-
>>> convex_api.get_balance(9)
15+
>>> from convex_api import API
16+
>>> convex = API('https://convex.world')
17+
>>> convex.get_balance(9)
1818
99396961137042
1919

2020
You can create a new emtpy account, with now balance:
2121

22-
>>> account = convex_api.create_account()
22+
>>> key_pair = KeyPair.create()
23+
>>> account = convex.create_account(key_pair)
2324
>>> account.address
2425
809
2526

2627
You can request some funds to the new account and then get the account information:
2728

2829
>>> convex_api.request_funds(1000000, account)
2930
1000000
30-
>>> convex_api.get_account_info(account)
31+
>>> convex.get_account_info(account)
3132
{'environment': {}, 'address': 809, 'is_library': False, 'is_actor': False, 'memory_size': 42, 'balance': 1000000, 'allowance': 0, 'sequence': 0, 'type': 'user'}
3233

3334

3435
You can export the accounts private key encoded as PKCS8 encrypt the key with a password:
3536

36-
>>> account.export_to_text('secret')
37+
>>> account.key_pair.export_to_text('secret')
3738
'-----BEGIN ENCRYPTED PRIVATE KEY-----\nMIGbMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAcBAiMY42UY4PXHAICCAAw\nDAYIKoZIhvcNAgkFADAdBglghkgBZQMEASoEEJpwDMicGbGj2iSJesktIVYEQBsp\nKMTAHzvUyw8jZRr8WSrmxH7938sjma8XWI6lgd9jwTZzcGamog7p3zatw0Wp+jFK\nKruWAZmIqhBZ/2ezDv8=\n-----END ENCRYPTED PRIVATE KEY-----\n'
3839

3940
>>> account.address
4041
809
4142

4243
To re-use your account again you need to import the encrypted private key and set the correct account address
4344

44-
>>> from convex_api import Account
45-
>>> account = Account.import_from_file('my_key.dat', 'secret', address=809)
45+
>>> from api import Account, KeyPair
46+
>>> key_pair = KeyPair.import_from_file('my_key.dat', 'secret')
47+
>>> account = Account.create(key_pair, 809)
4648

4749
To create a new address with the same account keys in your new or imported account object, you can do:
4850

49-
>>> new_account = convex_api.create_account(account)
51+
>>> new_account = convex.create_account(key_pair)
5052
>>> account.address
5153
809
5254
>>> new_account.address
@@ -55,37 +57,37 @@ To create a new address with the same account keys in your new or imported accou
5557
To use account names, where an account name is resolved to a fixed address. You can create or load
5658
an account based on it's name by doing the following:
5759

58-
>>> account = convex_api.setup_account('my-account-name', import_account)
60+
>>> account = convex.setup_account('my-account-name', key_pair)
5961
>>> account.address
6062
934
6163

62-
>>> convex_api.resolve_account_name('my-account-name')
64+
>>> convex.resolve_account_name('my-account-name')
6365
934
6466

65-
>>> same_account = convex_api.setup_account('my-account-name', import_account)
67+
>>> same_account = convex.setup_account('my-account-name', key_pair)
6668
>>> same_account.address
6769
934
6870

6971
To submit a transaction, use ConvexAPI.send(). This will cost a small about of juice, and reduce your balance
7072

71-
>>> convex_api.request_funds(1000000, account)
73+
>>> convex.request_funds(1000000, account)
7274
1000000
73-
>>> convex_api.send('(map inc [1 2 3 4])', account)
75+
>>> convex.send('(map inc [1 2 3 4])', account)
7476
{'value': [2, 3, 4, 5]}
75-
>>> convex_api.get_balance(account)
77+
>>> convex.get_balance(account)
7678
996360
7779

7880
To send a query a transaction, this is free and can be performed by any valid account address.
7981
So for example to query a balance of an account:
8082

81-
>>> convex_api.query(f'(balance {account.address})', account)
83+
>>> convex.query(f'(balance {account.address})', account)
8284
{'value': 996360}
8385

8486
# this is the same as above
85-
>>> convex_api.query(f'(balance {account.address})', account.address)
87+
>>> convex.query(f'(balance {account.address})', account.address)
8688
{'value': 996360}
8789

8890
# get the balance using one of the standard account addresses (#1)
89-
>>> convex_api.query(f'(balance {account.address})', 1)
91+
>>> convex.query(f'(balance {account.address})', 1)
9092
{'value': 996360}
9193

convex_api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
from convex_api.account import Account # noqa: F401
8-
from convex_api.convex_api import ConvexAPI # noqa: F401
8+
from convex_api.api import API # noqa: F401
99
from convex_api.key_pair import KeyPair # noqa: F401
1010

1111

convex_api/account.py

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ def __init__(self, key_pair, address, name=None):
1515
1616
Create a new account with a private key KeyPair.
1717
18-
You can also use the following static methods to create an Account object:
19-
20-
* :meth:`.create`
21-
2218
:param KeyPair key_pair: The public/private key of the account
2319
2420
:param int address: address of the account
@@ -28,16 +24,16 @@ def __init__(self, key_pair, address, name=None):
2824
.. code-block:: python
2925
3026
>>> # import convex-api
31-
>>> from convex_api import ConvexAPI, KeyPair, Account
27+
>>> from convex_api import API, KeyPair, Account
3228
3329
>>> # setup the network connection
34-
>>> convex_api = ConvexAPI('https://convex.world')
30+
>>> convex = API('https://convex.world')
3531
3632
>>> # create a random keypair
37-
>>> key_pair = KeyPair.create()
33+
>>> key_pair = KeyPair()
3834
3935
>>> # create a new account and address
40-
>>> account = convex_api.create_account(key_pair)
36+
>>> account = convex.create_account(key_pair)
4137
4238
>>> # export the private key to a file
4339
>>> key_pair.export_to_file('/tmp/my_account.pem', 'my secret password')
@@ -49,7 +45,7 @@ def __init__(self, key_pair, address, name=None):
4945
5046
>>> # now import the account and address for later use
5147
>>> key_pair = KeyPair.import_from_file('/tmp/my_account.pem', 'my secret password')
52-
>>> account = Account.create(key_pair, my_address)
48+
>>> account = Account(key_pair, my_address)
5349
5450
5551
"""
@@ -68,8 +64,8 @@ def sign(self, hash_text):
6864
6965
.. code-block:: python
7066
71-
>>> # create an account with no address
72-
>>> account = Account.create(key_pair)
67+
>>> # create an account
68+
>>> account = convex.create_account(key_pair)
7369
>>> # sign a given hash
7470
>>> sig = account.sign('7e2f1062f5fc51ed65a28b5945b49425aa42df6b7e67107efec357794096e05e')
7571
>>> print(sig)
@@ -102,7 +98,8 @@ def address(self):
10298
.. code-block:: python
10399
104100
>>> # create an account with the network
105-
>>> account = convex_api.create_account()
101+
>>> key_pair = KeyPair()
102+
>>> account = convex.create_account(key_pair)
106103
>>> print(account.address)
107104
42
108105
@@ -121,8 +118,9 @@ def address(self, value):
121118
.. code-block:: python
122119
123120
>>> # import the account keys
124-
>>> account = Account.import_from_mnemonic('my private key words ..')
121+
>>> key_pair = KeyPair.import_from_mnemonic('my private key words ..')
125122
123+
>>> account = convex.create_account(key_pair)
126124
>>> # set the address that was given to us when we created the account on the network
127125
>>> account.address = 42
128126
@@ -149,7 +147,7 @@ def public_key(self):
149147
.. code-block:: python
150148
151149
>>> # create an account with the network
152-
>>> account = convex_api.create_account(key_pair)
150+
>>> account = convex.create_account(key_pair)
153151
154152
>>> # show the public key as a hex string
155153
>>> print(account.public_key)
@@ -166,29 +164,3 @@ def key_pair(self):
166164
167165
"""
168166
return self._key_pair
169-
170-
@staticmethod
171-
def create(key_pair, address, name=None):
172-
"""
173-
174-
Create a new account with a random key and an empty address.
175-
176-
:param KeyPair key_pair: The public/private key of the account
177-
178-
:param int address: address of the account
179-
180-
:param str name: Optional name of the account
181-
182-
:returns: New Account object
183-
:rtype: Account
184-
185-
.. code-block:: python
186-
187-
>>> # create an account with no address
188-
>>> account = Account.create(key_pair)
189-
>> account.is_address
190-
False
191-
192-
193-
"""
194-
return Account(key_pair, address, name)

0 commit comments

Comments
 (0)