Skip to content

Commit efd2b14

Browse files
authored
Merge pull request #544 from singnet/development
v3.0.0 release
2 parents b8f6d67 + ef18a62 commit efd2b14

23 files changed

+355
-180
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ venv/
55
.idea/
66
__pycache__
77
blockchain/node_modules
8-
snet.egg-info/
9-
snet.cli.egg-info/
8+
snet_egg-info/
9+
snet_cli.egg-info/
1010
snet/cli/resources/node_modules
1111
snet/cli/resources/proto/*.py
1212
build/

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include snet/cli/resources/*
1+
recursive-include snet/cli/resources *
22

33
recursive-exclude * .git
44
recursive-exclude * node_modules

README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,25 @@ Backward compatibility for other Python versions is not guaranteed.
122122

123123
---
124124

125-
* Clone the git repository
125+
## Install the package in development mode
126+
127+
### Clone the git repository
128+
126129
```bash
127-
$ git clone https://github.com/singnet/snet-cli.git
128-
$ cd snet-cli/packages/snet_cli
130+
git clone https://github.com/singnet/snet-cli.git
131+
cd snet-cli
129132
```
130133

131-
*
132-
133-
* Install the package in development/editable mode
134+
```bash
135+
pip install -r requirements.txt
136+
```
137+
138+
```bash
139+
pip3 install .
140+
```
134141

135142
```bash
136-
$ pip3 install -e .
143+
snet -h
137144
```
138145

139146
### Building the Documentation in Markdown files

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ jsonschema==4.0.0
1818
eth-account==0.9.0
1919
trezor==0.13.8
2020
ledgerblue==0.1.48
21-
snet-contracts==0.2.1
21+
snet-contracts==1.0.0
2222
lighthouseweb3==0.1.4
23-
cryptography==43.0.3
23+
cryptography==44.0.1

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def run(self):
6767
},
6868
entry_points={
6969
'console_scripts': [
70-
'snet = snet.cli:main',
70+
'snet = snet.cli:main'
7171
],
7272
}
7373
)

snet/cli/arguments.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from snet.cli.commands.sdk_command import SDKCommand
1515
from snet.cli.config import Config, get_session_keys, get_session_network_keys_removable
1616
from snet.cli.identity import get_identity_types
17-
from snet.cli.utils.agix2cogs import stragix2cogs
17+
from snet.cli.utils.token2cogs import strtoken2cogs
1818
from snet.cli.utils.utils import type_converter
1919

2020

@@ -62,7 +62,7 @@ def add_root_options(parser, config):
6262
title="snet commands", metavar="COMMAND")
6363
subparsers.required = True
6464

65-
p = subparsers.add_parser("account", help="AGIX account")
65+
p = subparsers.add_parser("account", help="ASI(FET) account")
6666
add_mpe_account_options(p)
6767

6868
p = subparsers.add_parser("channel", help="Interact with SingularityNET payment channels")
@@ -236,7 +236,7 @@ def add_contract_options(parser):
236236

237237
contracts = get_all_abi_contract_files()
238238
for path in contracts:
239-
if "MultiPartyEscrow" in str(path) or "Registry" in str(path) or "SingularityNetToken" in str(path):
239+
if "MultiPartyEscrow" in str(path) or "Registry" in str(path) or "FetchToken" in str(path):
240240
contract_name = re.search(
241241
r"([^.]*)\.json", os.path.basename(path)).group(1)
242242
contract_p = subparsers.add_parser(
@@ -584,32 +584,32 @@ def add_p_snt_address_opt(p):
584584
p.set_defaults(fn="print_account")
585585
add_eth_call_arguments(p)
586586

587-
p = subparsers.add_parser("balance", help="Print balance of AGIX tokens and balance of MPE wallet")
588-
p.set_defaults(fn="print_agix_and_mpe_balances")
587+
p = subparsers.add_parser("balance", help="Print balance of ASI(FET) tokens and balance of MPE wallet")
588+
p.set_defaults(fn="print_token_and_mpe_balances")
589589
p.add_argument("--account", default=None, help="Account to print balance for (default is the current identity)")
590590
add_p_snt_address_opt(p)
591591
add_p_mpe_address_opt(p)
592592
add_eth_call_arguments(p)
593593

594-
p = subparsers.add_parser("deposit", help="Deposit AGIX tokens to MPE wallet")
594+
p = subparsers.add_parser("deposit", help="Deposit ASI(FET) tokens to MPE wallet")
595595
p.set_defaults(fn="deposit_to_mpe")
596-
p.add_argument("amount", type=stragix2cogs, help="Amount of AGIX tokens to deposit in MPE wallet", metavar="AMOUNT")
596+
p.add_argument("amount", type=strtoken2cogs, help="Amount of ASI(FET) tokens to deposit in MPE wallet", metavar="AMOUNT")
597597
add_p_snt_address_opt(p)
598598
add_p_mpe_address_opt(p)
599599
add_transaction_arguments(p)
600600

601-
p = subparsers.add_parser("withdraw", help="Withdraw AGIX tokens from MPE wallet")
601+
p = subparsers.add_parser("withdraw", help="Withdraw ASI(FET) tokens from MPE wallet")
602602
p.set_defaults(fn="withdraw_from_mpe")
603-
p.add_argument("amount", type=stragix2cogs, help="Amount of AGIX tokens to withdraw from MPE wallet", metavar="AMOUNT")
603+
p.add_argument("amount", type=strtoken2cogs, help="Amount of ASI(FET) tokens to withdraw from MPE wallet", metavar="AMOUNT")
604604
add_p_mpe_address_opt(p)
605605
add_transaction_arguments(p)
606606

607-
p = subparsers.add_parser("transfer", help="Transfer AGIX tokens inside MPE wallet")
607+
p = subparsers.add_parser("transfer", help="Transfer ASI(FET) tokens inside MPE wallet")
608608
p.set_defaults(fn="transfer_in_mpe")
609609
p.add_argument("receiver", help="Address of the receiver", metavar="RECEIVER")
610610
p.add_argument("amount",
611-
type=stragix2cogs,
612-
help="Amount of AGIX tokens to be transferred to another account inside MPE wallet",
611+
type=strtoken2cogs,
612+
help="Amount of ASI(FET) tokens to be transferred to another account inside MPE wallet",
613613
metavar="AMOUNT")
614614
add_p_mpe_address_opt(p)
615615
add_transaction_arguments(p)
@@ -664,8 +664,8 @@ def add_p_open_channel_basic(p):
664664
add_group_name(p)
665665

666666
p.add_argument("amount",
667-
type=stragix2cogs,
668-
help="Amount of AGIX tokens to put in the new channel",
667+
type=strtoken2cogs,
668+
help="Amount of ASI(FET) tokens to put in the new channel",
669669
metavar="AMOUNT")
670670
# p.add_argument("group_name",
671671
# default=None,
@@ -709,8 +709,8 @@ def add_p_set_for_extend_add(_p):
709709
title="Expiration and amount")
710710
add_p_expiration(expiration_amount_g, is_optional=True)
711711
expiration_amount_g.add_argument("--amount",
712-
type=stragix2cogs,
713-
help="Amount of AGIX tokens to add to the channel")
712+
type=strtoken2cogs,
713+
help="Amount of ASI(FET) tokens to add to the channel")
714714
add_p_mpe_address_opt(p)
715715
add_transaction_arguments(p)
716716

@@ -920,8 +920,8 @@ def add_mpe_service_options(parser):
920920
nargs='*',
921921
help="Endpoints for the first group")
922922
p.add_argument("--fixed-price",
923-
type=stragix2cogs,
924-
help="Set fixed price in AGIX token for all methods")
923+
type=strtoken2cogs,
924+
help="Set fixed price in ASI(FET) token for all methods")
925925

926926
p.add_argument("--encoding",
927927
default="proto",
@@ -950,8 +950,8 @@ def add_mpe_service_options(parser):
950950
p.add_argument("group_name",
951951
help="group name for fixed price method")
952952
p.add_argument("price",
953-
type=stragix2cogs,
954-
help="Set fixed price in AGIX token for all methods",
953+
type=strtoken2cogs,
954+
help="Set fixed price in ASI(FET) token for all methods",
955955
metavar="PRICE")
956956
add_p_metadata_file_opt(p)
957957

@@ -970,8 +970,8 @@ def add_mpe_service_options(parser):
970970
)
971971

972972
p.add_argument("price",
973-
type=stragix2cogs,
974-
help="Set fixed price in AGIX token for all methods",
973+
type=strtoken2cogs,
974+
help="Set fixed price in ASI(FET) token for all methods",
975975
metavar="PRICE")
976976
add_p_metadata_file_opt(p)
977977

snet/cli/commands/commands.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ def get_identity(self):
166166
return RpcIdentityProvider(self.w3, self.get_wallet_index())
167167
if identity_type == "mnemonic":
168168
return MnemonicIdentityProvider(self.w3, self.config.get_session_field("mnemonic"), self.get_wallet_index())
169-
if identity_type == "trezor":
170-
return TrezorIdentityProvider(self.w3, self.get_wallet_index())
169+
# if identity_type == "trezor":
170+
# return TrezorIdentityProvider(self.w3, self.get_wallet_index())
171171
if identity_type == "ledger":
172172
return LedgerIdentityProvider(self.w3, self.get_wallet_index())
173173
if identity_type == "key":
@@ -358,8 +358,8 @@ def populate_contract_address(self, rez, key):
358358
w3=self.w3, contract_name="Registry")
359359
rez[key]['default_multipartyescrow_at'] = read_default_contract_address(
360360
w3=self.w3, contract_name="MultiPartyEscrow")
361-
rez[key]['default_singularitynettoken_at'] = read_default_contract_address(
362-
w3=self.w3, contract_name="SingularityNetToken")
361+
rez[key]['default_fetchtoken_at'] = read_default_contract_address(
362+
w3=self.w3, contract_name="FetchToken")
363363
except Exception as e:
364364
pass
365365
return

snet/cli/commands/mpe_account.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from snet.cli.commands.commands import BlockchainCommand
2-
from snet.cli.utils.agix2cogs import cogs2stragix
2+
from snet.cli.utils.token2cogs import cogs2strtoken
33

44

55
class MPEAccountCommand(BlockchainCommand):
@@ -8,31 +8,31 @@ def print_account(self):
88
self.check_ident()
99
self._printout(self.ident.address)
1010

11-
def print_agix_and_mpe_balances(self):
12-
""" Print balance of ETH, AGIX, and MPE wallet """
11+
def print_token_and_mpe_balances(self):
12+
""" Print balance of ETH, ASI(FET), and MPE wallet """
1313
self.check_ident()
1414
if self.args.account:
1515
account = self.args.account
1616
else:
1717
account = self.ident.address
1818
eth_wei = self.w3.eth.get_balance(account)
19-
agix_cogs = self.call_contract_command("SingularityNetToken", "balanceOf", [account])
19+
token_cogs = self.call_contract_command("FetchToken", "balanceOf", [account])
2020
mpe_cogs = self.call_contract_command("MultiPartyEscrow", "balances", [account])
2121

2222
# we cannot use _pprint here because it doesn't conserve order yet
2323
self._printout(" account: %s"%account)
2424
self._printout(" ETH: %s"%self.w3.from_wei(eth_wei, 'ether'))
25-
self._printout(" AGIX: %s"%cogs2stragix(agix_cogs))
26-
self._printout(" MPE: %s"%cogs2stragix(mpe_cogs))
25+
self._printout(" ASI(FET): %s"%cogs2strtoken(token_cogs))
26+
self._printout(" MPE: %s"%cogs2strtoken(mpe_cogs))
2727

2828
def deposit_to_mpe(self):
2929
self.check_ident()
3030
amount = self.args.amount
3131
mpe_address = self.get_mpe_address()
3232

33-
already_approved = self.call_contract_command("SingularityNetToken", "allowance", [self.ident.address, mpe_address])
33+
already_approved = self.call_contract_command("FetchToken", "allowance", [self.ident.address, mpe_address])
3434
if already_approved < amount:
35-
self.transact_contract_command("SingularityNetToken", "approve", [mpe_address, amount])
35+
self.transact_contract_command("FetchToken", "approve", [mpe_address, amount])
3636
self.transact_contract_command("MultiPartyEscrow", "deposit", [amount])
3737

3838
def withdraw_from_mpe(self):

snet/cli/commands/mpe_channel.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
from snet.cli.commands.commands import OrganizationCommand
1515
from snet.cli.metadata.service import mpe_service_metadata_from_json, load_mpe_service_metadata
1616
from snet.cli.metadata.organization import OrganizationMetadata
17-
from snet.cli.utils.agix2cogs import cogs2stragix
17+
from snet.cli.utils.token2cogs import cogs2strtoken
1818
from snet.cli.utils.ipfs_utils import get_from_ipfs_and_checkhash
1919
from snet.cli.utils.utils import abi_decode_struct_to_dict, abi_get_element_by_name, \
20-
compile_proto, type_converter, bytesuri_to_hash, get_file_from_filecoin, download_and_safe_extract_proto
20+
compile_proto, type_converter, bytesuri_to_hash, get_file_from_filecoin, download_and_safe_extract_proto, \
21+
check_training_in_proto
2122

2223

2324
# we inherit MPEServiceCommand because we need _get_service_metadata_from_registry
@@ -37,7 +38,7 @@ def _get_channels_cache_file(self):
3738

3839
def _update_channels_cache(self):
3940
channels = []
40-
last_read_block = get_contract_deployment_block(self.ident.w3, "MultiPartyEscrow")
41+
last_read_block = get_contract_deployment_block(self.ident.w3, "MultiPartyEscrow") - 1
4142
channels_file = self._get_channels_cache_file()
4243

4344
if not channels_file.exists():
@@ -58,7 +59,7 @@ def _update_channels_cache(self):
5859
current_block_number = self.ident.w3.eth.block_number
5960

6061
if last_read_block < current_block_number:
61-
new_channels = self._get_all_opened_channels_from_blockchain(last_read_block, current_block_number)
62+
new_channels = self._get_all_opened_channels_from_blockchain(last_read_block + 1, current_block_number)
6263
channels = channels + new_channels
6364
last_read_block = current_block_number
6465

@@ -286,7 +287,7 @@ def _open_channel_for_org(self, metadata):
286287
"MultiPartyEscrow", "balances", [self.ident.address])
287288
if mpe_cogs < self.args.amount:
288289
raise Exception(
289-
"insufficient funds. You MPE balance is %s AGIX " % cogs2stragix(mpe_cogs))
290+
"insufficient funds. You MPE balance is %s ASI(FET) " % cogs2strtoken(mpe_cogs))
290291

291292
group_id = base64.b64decode(metadata.get_group_id_by_group_name(self.args.group_name))
292293
if not group_id:
@@ -496,7 +497,7 @@ def _print_channels(self, channels, filters: list[str] = None):
496497
for channel_id in channels_ids:
497498
channel = self._get_channel_state_from_blockchain(channel_id)
498499
channel["channel_id"] = channel_id
499-
channel["value"] = cogs2stragix(channel["value"])
500+
channel["value"] = cogs2strtoken(channel["value"])
500501
channel["group_id"] = base64.b64encode(channel["groupId"]).decode("ascii")
501502
self._printout(self._convert_channel_dict_to_str(channel, filters))
502503

@@ -602,9 +603,10 @@ def _init_or_update_service_if_needed(self, metadata, service_registration):
602603
os.makedirs(spec_dir, mode=0o700)
603604
service_api_source = metadata.get("service_api_source") or metadata.get("model_ipfs_hash")
604605
download_and_safe_extract_proto(service_api_source, spec_dir, self._get_ipfs_client())
606+
training_added = check_training_in_proto(spec_dir)
605607

606608
# compile .proto files
607-
if not compile_proto(Path(spec_dir), service_dir):
609+
if not compile_proto(Path(spec_dir), service_dir, add_training = training_added):
608610
raise Exception("Fail to compile %s/*.proto" % spec_dir)
609611

610612
# save service_metadata.json in channel_dir

snet/cli/commands/mpe_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from eth_account.messages import encode_defunct
77

88
from snet.cli.commands.mpe_channel import MPEChannelCommand
9-
from snet.cli.utils.agix2cogs import cogs2stragix
9+
from snet.cli.utils.token2cogs import cogs2strtoken
1010
from snet.cli.utils.proto_utils import import_protobuf_from_dir, switch_to_json_payload_encoding
1111
from snet.cli.utils.utils import open_grpc_channel, rgetattr, RESOURCES_PATH
1212

@@ -303,7 +303,7 @@ def call_server_statelessly_with_params(self, params, group_name):
303303
server_state = self._get_channel_state_from_server(grpc_channel, channel_id)
304304

305305
proceed = self.args.yes or input(
306-
"Price for this call will be %s AGIX (use -y to remove this warning). Proceed? (y/n): " % (cogs2stragix(price))) == "y"
306+
"Price for this call will be %s ASI(FET) (use -y to remove this warning). Proceed? (y/n): " % (cogs2strtoken(price))) == "y"
307307
if not proceed:
308308
self._error("Cancelled")
309309

0 commit comments

Comments
 (0)