mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-09-20 16:08:51 +03:00
Merge remote-tracking branch 'remotes/origin/release/1.4.0' into gw.nft1_more_tests
This commit is contained in:
commit
be48c11809
@ -1 +1 @@
|
||||
Subproject commit a3577b36ea2be2e90916d9ea7aaac245b555a0dc
|
||||
Subproject commit 09b81062e0ac106265b7d467580bf3b42ecd9d95
|
@ -595,7 +595,9 @@ def nft_mint_cmd(
|
||||
@click.option("-f", "--fingerprint", help="Set the fingerprint to specify which wallet to use", type=int)
|
||||
@click.option("-i", "--id", help="Id of the NFT wallet to use", type=int, required=True)
|
||||
@click.option("-ni", "--nft-coin-id", help="Id of the NFT coin to add the URI to", type=str, required=True)
|
||||
@click.option("-u", "--uri", help="URI to add to the NFT", type=str, required=True)
|
||||
@click.option("-u", "--uri", help="URI to add to the NFT", type=str)
|
||||
@click.option("-mu", "--metadata-uri", help="Metadata URI to add to the NFT", type=str)
|
||||
@click.option("-lu", "--license-uri", help="License URI to add to the NFT", type=str)
|
||||
@click.option(
|
||||
"-m",
|
||||
"--fee",
|
||||
@ -611,6 +613,8 @@ def nft_add_uri_cmd(
|
||||
id: int,
|
||||
nft_coin_id: str,
|
||||
uri: str,
|
||||
metadata_uri: str,
|
||||
license_uri: str,
|
||||
fee: str,
|
||||
) -> None:
|
||||
import asyncio
|
||||
@ -620,6 +624,8 @@ def nft_add_uri_cmd(
|
||||
"wallet_id": id,
|
||||
"nft_coin_id": nft_coin_id,
|
||||
"uri": uri,
|
||||
"metadata_uri": metadata_uri,
|
||||
"license_uri": license_uri,
|
||||
"fee": fee,
|
||||
}
|
||||
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, add_uri_to_nft))
|
||||
|
@ -548,7 +548,7 @@ async def print_balances(args: dict, wallet_client: WalletRpcClient, fingerprint
|
||||
print(f"{indent}{'-Pending Total Balance:'.ljust(23)} " f"{unconfirmed_wallet_balance}")
|
||||
print(f"{indent}{'-Spendable:'.ljust(23)} {spendable_balance}")
|
||||
print(f"{indent}{'-Type:'.ljust(23)} {typ.name}")
|
||||
if typ == WalletType.DISTRIBUTED_ID:
|
||||
if typ == WalletType.DECENTRALIZED_ID:
|
||||
get_did_response = await wallet_client.get_did_id(wallet_id)
|
||||
my_did = get_did_response["my_did"]
|
||||
print(f"{indent}{'-DID ID:'.ljust(23)} {my_did}")
|
||||
@ -745,9 +745,23 @@ async def add_uri_to_nft(args: Dict, wallet_client: WalletRpcClient, fingerprint
|
||||
wallet_id = args["wallet_id"]
|
||||
nft_coin_id = args["nft_coin_id"]
|
||||
uri = args["uri"]
|
||||
metadata_uri = args["metadata_uri"]
|
||||
license_uri = args["license_uri"]
|
||||
if len([x for x in (uri, metadata_uri, license_uri) if x is not None]) > 1:
|
||||
raise ValueError("You must provide only one of the URI flags")
|
||||
if uri is not None and len(uri) > 0:
|
||||
key = "u"
|
||||
uri_value = uri
|
||||
elif metadata_uri is not None and len(metadata_uri) > 0:
|
||||
key = "mu"
|
||||
uri_value = metadata_uri
|
||||
elif license_uri is not None and len(license_uri) > 0:
|
||||
key = "lu"
|
||||
uri_value = license_uri
|
||||
else:
|
||||
raise ValueError("You must provide at least one of the URI flags")
|
||||
fee: int = int(Decimal(args["fee"]) * units["chia"])
|
||||
key = args.get("meta_uri", "u")
|
||||
response = await wallet_client.add_uri_to_nft(wallet_id, nft_coin_id, key, uri, fee)
|
||||
response = await wallet_client.add_uri_to_nft(wallet_id, nft_coin_id, key, uri_value, fee)
|
||||
spend_bundle = response["spend_bundle"]
|
||||
print(f"URI added successfully with spend bundle: {spend_bundle}")
|
||||
except Exception as e:
|
||||
|
@ -1129,7 +1129,7 @@ class WalletRpcApi:
|
||||
assert self.service.wallet_state_manager is not None
|
||||
wallet_id = int(request["wallet_id"])
|
||||
wallet: DIDWallet = self.service.wallet_state_manager.wallets[wallet_id]
|
||||
if wallet.type() == WalletType.DISTRIBUTED_ID:
|
||||
if wallet.type() == WalletType.DECENTRALIZED_ID:
|
||||
await wallet.set_name(str(request["name"]))
|
||||
return {"success": True, "wallet_id": wallet_id}
|
||||
else:
|
||||
@ -1165,19 +1165,22 @@ class WalletRpcApi:
|
||||
async def did_update_metadata(self, request):
|
||||
wallet_id = int(request["wallet_id"])
|
||||
wallet: DIDWallet = self.service.wallet_state_manager.wallets[wallet_id]
|
||||
if wallet.type() != WalletType.DECENTRALIZED_ID.value:
|
||||
return {"success": False, "error": f"Wallet with id {wallet_id} is not a DID one"}
|
||||
metadata: Dict[str, str] = {}
|
||||
success: bool = False
|
||||
if "metadata" in request:
|
||||
if type(request["metadata"]) is dict:
|
||||
metadata = request["metadata"]
|
||||
if "metadata" in request and type(request["metadata"]) is dict:
|
||||
metadata = request["metadata"]
|
||||
async with self.service.wallet_state_manager.lock:
|
||||
update_success = await wallet.update_metadata(metadata)
|
||||
# Update coin with new ID info
|
||||
if update_success:
|
||||
spend_bundle = await wallet.create_update_spend()
|
||||
if spend_bundle is not None:
|
||||
success = True
|
||||
return {"success": success}
|
||||
return {"wallet_id": wallet_id, "success": True, "spend_bundle": spend_bundle}
|
||||
else:
|
||||
return {"success": False, "error": "Couldn't create an update spend bundle."}
|
||||
else:
|
||||
return {"success": False, "error": f"Couldn't update metadata with input: {metadata}"}
|
||||
|
||||
async def did_get_did(self, request):
|
||||
wallet_id = int(request["wallet_id"])
|
||||
@ -1449,7 +1452,7 @@ class WalletRpcApi:
|
||||
did_wallets_by_did_id: Dict[bytes32, uint32] = {
|
||||
wallet.did_info.origin_coin.name(): wallet.id()
|
||||
for wallet in all_wallets
|
||||
if wallet.type() == uint8(WalletType.DISTRIBUTED_ID) and wallet.did_info.origin_coin is not None
|
||||
if wallet.type() == uint8(WalletType.DECENTRALIZED_ID) and wallet.did_info.origin_coin is not None
|
||||
}
|
||||
did_nft_wallets: List[Dict] = []
|
||||
for wallet in all_wallets:
|
||||
|
@ -94,7 +94,7 @@ class DIDWallet:
|
||||
)
|
||||
info_as_string = json.dumps(self.did_info.to_json_dict())
|
||||
self.wallet_info = await wallet_state_manager.user_store.create_wallet(
|
||||
name, WalletType.DISTRIBUTED_ID.value, info_as_string
|
||||
name, WalletType.DECENTRALIZED_ID.value, info_as_string
|
||||
)
|
||||
if self.wallet_info is None:
|
||||
raise ValueError("Internal Error")
|
||||
@ -189,7 +189,7 @@ class DIDWallet:
|
||||
self.check_existed_did()
|
||||
info_as_string = json.dumps(self.did_info.to_json_dict())
|
||||
self.wallet_info = await wallet_state_manager.user_store.create_wallet(
|
||||
name, WalletType.DISTRIBUTED_ID.value, info_as_string
|
||||
name, WalletType.DECENTRALIZED_ID.value, info_as_string
|
||||
)
|
||||
await self.wallet_state_manager.add_new_wallet(self, self.wallet_info.id)
|
||||
await self.save_info(self.did_info, False)
|
||||
@ -258,7 +258,7 @@ class DIDWallet:
|
||||
info_as_string = json.dumps(self.did_info.to_json_dict())
|
||||
|
||||
self.wallet_info = await wallet_state_manager.user_store.create_wallet(
|
||||
name, WalletType.DISTRIBUTED_ID.value, info_as_string, in_transaction=True
|
||||
name, WalletType.DECENTRALIZED_ID.value, info_as_string, in_transaction=True
|
||||
)
|
||||
await self.wallet_state_manager.add_new_wallet(self, self.wallet_info.id, in_transaction=True)
|
||||
await self.wallet_state_manager.update_wallet_puzzle_hashes(self.wallet_info.id, in_transaction=True)
|
||||
@ -298,7 +298,7 @@ class DIDWallet:
|
||||
|
||||
@classmethod
|
||||
def type(cls) -> uint8:
|
||||
return uint8(WalletType.DISTRIBUTED_ID)
|
||||
return uint8(WalletType.DECENTRALIZED_ID)
|
||||
|
||||
def id(self):
|
||||
return self.wallet_info.id
|
||||
@ -1292,7 +1292,7 @@ class DIDWallet:
|
||||
"""
|
||||
max_num = 0
|
||||
for wallet in self.wallet_state_manager.wallets.values():
|
||||
if wallet.type() == WalletType.DISTRIBUTED_ID:
|
||||
if wallet.type() == WalletType.DECENTRALIZED_ID:
|
||||
matched = re.search(r"^Profile (\d+)$", wallet.wallet_info.name)
|
||||
if matched and int(matched.group(1)) > max_num:
|
||||
max_num = int(matched.group(1))
|
||||
@ -1305,7 +1305,7 @@ class DIDWallet:
|
||||
"""
|
||||
for wallet in self.wallet_state_manager.wallets.values():
|
||||
if (
|
||||
wallet.type() == WalletType.DISTRIBUTED_ID
|
||||
wallet.type() == WalletType.DECENTRALIZED_ID
|
||||
and self.did_info.origin_coin.name() == wallet.did_info.origin_coin.name()
|
||||
):
|
||||
self.log.warning(f"DID {self.did_info.origin_coin} already existed, ignore the wallet creation.")
|
||||
|
@ -326,7 +326,7 @@ class NFTWallet:
|
||||
did_id = self.did_id
|
||||
for _, wallet in self.wallet_state_manager.wallets.items():
|
||||
self.log.debug("Checking wallet type %s", wallet.type())
|
||||
if wallet.type() == WalletType.DISTRIBUTED_ID:
|
||||
if wallet.type() == WalletType.DECENTRALIZED_ID:
|
||||
self.log.debug("Found a DID wallet, checking did: %r == %r", wallet.get_my_DID(), did_id)
|
||||
if bytes32.fromhex(wallet.get_my_DID()) == did_id:
|
||||
self.log.debug("Creating announcement from DID for nft_id: %s", nft_id)
|
||||
|
@ -679,7 +679,7 @@ class TradeManager:
|
||||
return await NFTWallet.make_nft1_offer(self.wallet_state_manager, offer_dict, driver_dict, fee)
|
||||
return None
|
||||
|
||||
async def check_for_owner_change_in_drivers(self, puzzle_info: PuzzleInfo, driver_info: PuzzleInfo) -> bool:
|
||||
def check_for_owner_change_in_drivers(self, puzzle_info: PuzzleInfo, driver_info: PuzzleInfo) -> bool:
|
||||
if puzzle_info.check_type(
|
||||
[
|
||||
AssetType.SINGLETON.value,
|
||||
|
@ -17,7 +17,7 @@ class WalletType(IntEnum):
|
||||
CUSTODY = 5
|
||||
CAT = 6
|
||||
RECOVERABLE = 7
|
||||
DISTRIBUTED_ID = 8
|
||||
DECENTRALIZED_ID = 8
|
||||
POOLING_WALLET = 9
|
||||
NFT = 10
|
||||
|
||||
|
@ -206,7 +206,7 @@ class WalletStateManager:
|
||||
)
|
||||
elif wallet_info.type == WalletType.RATE_LIMITED:
|
||||
wallet = await RLWallet.create(self, wallet_info)
|
||||
elif wallet_info.type == WalletType.DISTRIBUTED_ID:
|
||||
elif wallet_info.type == WalletType.DECENTRALIZED_ID:
|
||||
wallet = await DIDWallet.create(
|
||||
self,
|
||||
self.main_wallet,
|
||||
@ -746,7 +746,7 @@ class WalletStateManager:
|
||||
if wallet_id is None:
|
||||
if did_id is not None:
|
||||
found_did: bool = False
|
||||
for wallet_info in await self.get_all_wallet_info_entries(wallet_type=WalletType.DISTRIBUTED_ID):
|
||||
for wallet_info in await self.get_all_wallet_info_entries(wallet_type=WalletType.DECENTRALIZED_ID):
|
||||
did_info: DIDInfo = DIDInfo.from_json_dict(json.loads(wallet_info.data))
|
||||
if did_info.origin_coin is not None and did_info.origin_coin.name() == did_id:
|
||||
found_did = True
|
||||
@ -1213,7 +1213,7 @@ class WalletStateManager:
|
||||
)
|
||||
await self.coin_store.add_coin_record(coin_record_1)
|
||||
|
||||
if wallet_type == WalletType.CAT or wallet_type == WalletType.DISTRIBUTED_ID:
|
||||
if wallet_type == WalletType.CAT or wallet_type == WalletType.DECENTRALIZED_ID:
|
||||
wallet = self.wallets[wallet_id]
|
||||
await wallet.coin_added(coin, height)
|
||||
|
||||
|
@ -666,7 +666,7 @@ class TestDIDWallet:
|
||||
# Get the new DID wallet
|
||||
did_wallets = list(
|
||||
filter(
|
||||
lambda w: (w.type == WalletType.DISTRIBUTED_ID),
|
||||
lambda w: (w.type == WalletType.DECENTRALIZED_ID),
|
||||
await wallet_node_2.wallet_state_manager.get_all_wallet_info_entries(),
|
||||
)
|
||||
)
|
||||
|
@ -745,6 +745,7 @@ async def test_did_endpoints(wallet_rpc_environment: WalletRpcTestEnvironment):
|
||||
wallet_2_node: WalletNode = env.wallet_2.node
|
||||
wallet_1_rpc: WalletRpcClient = env.wallet_1.rpc_client
|
||||
full_node_api: FullNodeSimulator = env.full_node.api
|
||||
wallet_1_id = wallet_1.id()
|
||||
|
||||
await generate_funds(env.full_node.api, env.wallet_1, 5)
|
||||
|
||||
@ -767,7 +768,7 @@ async def test_did_endpoints(wallet_rpc_environment: WalletRpcTestEnvironment):
|
||||
assert res["success"]
|
||||
assert res["name"] == new_wallet_name
|
||||
with pytest.raises(ValueError, match="Wallet id 1 is not a DID wallet"):
|
||||
await wallet_1_rpc.did_set_wallet_name(wallet_1.id(), new_wallet_name)
|
||||
await wallet_1_rpc.did_set_wallet_name(wallet_1_id, new_wallet_name)
|
||||
|
||||
# Check DID ID
|
||||
res = await wallet_1_rpc.get_did_id(did_wallet_id_0)
|
||||
@ -791,6 +792,8 @@ async def test_did_endpoints(wallet_rpc_environment: WalletRpcTestEnvironment):
|
||||
await farm_transaction_block(full_node_api, wallet_1_node)
|
||||
|
||||
# Update metadata
|
||||
with pytest.raises(ValueError, match="Wallet with id 1 is not a DID one"):
|
||||
await wallet_1_rpc.update_did_metadata(wallet_1_id, {"Twitter": "Https://test"})
|
||||
res = await wallet_1_rpc.update_did_metadata(did_wallet_id_0, {"Twitter": "Https://test"})
|
||||
assert res["success"]
|
||||
|
||||
@ -815,7 +818,7 @@ async def test_did_endpoints(wallet_rpc_environment: WalletRpcTestEnvironment):
|
||||
|
||||
did_wallets = list(
|
||||
filter(
|
||||
lambda w: (w.type == WalletType.DISTRIBUTED_ID),
|
||||
lambda w: (w.type == WalletType.DECENTRALIZED_ID),
|
||||
await wallet_2_node.wallet_state_manager.get_all_wallet_info_entries(),
|
||||
)
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user