mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2026-09-05 02:24:21 -05:00
Merge pull request #11863 from Chia-Network/paninaro.nft_get_wallets_with_dids_rpc
Added nft_get_wallets_with_dids RPC to simplify the discovery
This commit is contained in:
@@ -136,6 +136,7 @@ class WalletRpcApi:
|
||||
"/nft_mint_nft": self.nft_mint_nft,
|
||||
"/nft_get_nfts": self.nft_get_nfts,
|
||||
"/nft_get_by_did": self.nft_get_by_did,
|
||||
"/nft_get_wallets_with_dids": self.nft_get_wallets_with_dids,
|
||||
"/nft_get_info": self.nft_get_info,
|
||||
"/nft_transfer_nft": self.nft_transfer_nft,
|
||||
"/nft_add_uri": self.nft_add_uri,
|
||||
@@ -1399,6 +1400,32 @@ class WalletRpcApi:
|
||||
return {"wallet_id": wallet.wallet_id, "success": True}
|
||||
return {"error": f"Cannot find a NFT wallet DID = {did_id}", "success": False}
|
||||
|
||||
async def nft_get_wallets_with_dids(self, request) -> Dict:
|
||||
assert self.service.wallet_state_manager is not None
|
||||
all_wallets = self.service.wallet_state_manager.wallets.values()
|
||||
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
|
||||
}
|
||||
did_nft_wallets: List[Dict] = []
|
||||
for wallet in all_wallets:
|
||||
if isinstance(wallet, NFTWallet):
|
||||
nft_wallet_did: Optional[bytes32] = wallet.get_did()
|
||||
if nft_wallet_did is not None:
|
||||
did_wallet_id: uint32 = did_wallets_by_did_id.get(nft_wallet_did, uint32(0))
|
||||
if did_wallet_id == 0:
|
||||
log.warning(f"NFT wallet {wallet.id()} has DID {nft_wallet_did.hex()} but no DID wallet")
|
||||
else:
|
||||
did_nft_wallets.append(
|
||||
{
|
||||
"wallet_id": wallet.id(),
|
||||
"did_id": nft_wallet_did.hex(),
|
||||
"did_wallet_id": did_wallet_id,
|
||||
}
|
||||
)
|
||||
return {"success": True, "nft_wallets": did_nft_wallets}
|
||||
|
||||
async def nft_transfer_nft(self, request):
|
||||
assert self.service.wallet_state_manager is not None
|
||||
wallet_id = uint32(request["wallet_id"])
|
||||
|
||||
@@ -599,6 +599,13 @@ async def test_nft_with_did_wallet_creation(two_wallet_nodes: Any, trusted: Any)
|
||||
assert nft_wallet_0_id == res["wallet_id"]
|
||||
await time_out_assert(10, wallet_0.get_unconfirmed_balance, 5999999999999)
|
||||
await time_out_assert(10, wallet_0.get_confirmed_balance, 5999999999999)
|
||||
|
||||
res = await api_0.nft_get_wallets_with_dids({})
|
||||
assert res.get("success")
|
||||
assert res.get("nft_wallets") == [
|
||||
{"wallet_id": nft_wallet_0_id, "did_id": hex_did_id, "did_wallet_id": did_wallet.id()}
|
||||
]
|
||||
|
||||
# Create a NFT with DID
|
||||
nft_ph: bytes32 = await wallet_0.get_new_puzzlehash()
|
||||
resp = await api_0.nft_mint_nft(
|
||||
|
||||
Reference in New Issue
Block a user