Skip to content

Commit

Permalink
Adding Walletconnect endpoints for DIDs, Datalayer, and NFT Bulk Mint (
Browse files Browse the repository at this point in the history
…#2521)

* added walletconnect endpoints for datalayer and dids

* added nft_mint_bulk and push_tx walletconnect endpoints

* added permissionRequest walletconnect command

* cleaned up requestPermissions and got it mostly working

* made requestPermission filter out commands that don't allow bypass

* Fixed prettier errors

* Checkpoint

* Checkpoint

* Checkpoint

* Checkpoint

* Checkpoint

---------

Co-authored-by: Gaerax <[email protected]>
  • Loading branch information
ChiaMineJP and Gaerax authored Nov 13, 2024
1 parent 0ae6dbc commit b9b26fd
Show file tree
Hide file tree
Showing 18 changed files with 2,212 additions and 28 deletions.
198 changes: 198 additions & 0 deletions packages/api-react/src/services/dataLayer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
import { DataLayer } from '@chia-network/api';

import api from '../api';
import { query, mutation } from '../utils/reduxToolkitEndpointAbstractions';

export const apiWithTag = api.enhanceEndpoints({
addTagTypes: [
'OwnedDataStores',
'Roots',
'RootHistories',
'LocalRoots',
'Mirrors',
'Keys',
'KeysValues',
'Values',
'Ancestors',
'SyncStatus',
'KvDiff',
'Subscriptions',
'Offers',
'StoreMirrors',
'PendingRoots',
'Plugins',
'Files',
],
});
export const dataLayerApi = apiWithTag.injectEndpoints({
endpoints: (build) => ({
addMirror: mutation(build, DataLayer, 'addMirror', {
invalidatesTags: (_result, _error, { id }) => [
{ type: 'StoreMirrors', id: 'LIST' },
{ type: 'StoreMirrors', id },
],
}),

addMissingFiles: mutation(build, DataLayer, 'addMissingFiles', {
invalidatesTags: (_result, _error, { ids }) => (ids ? ids.map((id: string) => ({ type: 'Files', id })) : []),
}),

batchUpdate: mutation(build, DataLayer, 'batchUpdate', {
invalidatesTags: (_result, _error, { id }) => [
{ type: 'Keys', id },
{ type: 'KeysValues', id },
],
}),

cancelOffer: mutation(build, DataLayer, 'cancelOffer', {
invalidatesTags: (_result, _error, { tradeId }) => [{ type: 'Offers', id: tradeId }],
}),

checkPlugins: query(build, DataLayer, 'checkPlugins', {
providesTags: [{ type: 'Plugins' }],
}),

clearPendingRoots: mutation(build, DataLayer, 'clearPendingRoots', {
invalidatesTags: (_result, _error, { storeId }) => [{ type: 'PendingRoots', id: storeId }],
}),

createDataStore: mutation(build, DataLayer, 'createDataStore', {
invalidatesTags: [{ type: 'OwnedDataStores' }],
}),

deleteKey: mutation(build, DataLayer, 'deleteKey', {
invalidatesTags: (_result, _error, { id }) => [
{ type: 'Keys', id },
{ type: 'KeysValues', id },
],
}),

deleteMirror: mutation(build, DataLayer, 'deleteMirror', {
invalidatesTags: (_result, _error, { coinId: id }) => [{ type: 'Mirrors', id }],
}),

getAncestors: query(build, DataLayer, 'getAncestors', {
providesTags: (_result, _error, { id }) => [{ type: 'Ancestors', id }],
}),

getKeys: query(build, DataLayer, 'getKeys', {
providesTags: (_result, _error, { id }) => [{ type: 'Keys', id }],
}),

getKeysValues: query(build, DataLayer, 'getKeysValues', {
providesTags: (_result, _error, { id }) => [{ type: 'KeysValues', id }],
}),

getKvDiff: query(build, DataLayer, 'getKvDiff', {
providesTags: [{ type: 'KvDiff' }],
}),

getLocalRoot: query(build, DataLayer, 'getLocalRoot', {
providesTags: (_result, _error, { id }) => [{ type: 'LocalRoots', id }],
}),

getMirrors: query(build, DataLayer, 'getMirrors', {
providesTags: (_result, _error, { id }) => [{ type: 'Mirrors', id }],
}),

getOwnedStores: query(build, DataLayer, 'getOwnedStores', {
providesTags: [{ type: 'OwnedDataStores' }],
}),

getRoot: query(build, DataLayer, 'getRoot', {
providesTags: (_result, _error, { id }) => [{ type: 'Roots', id }],
}),

getRoots: query(build, DataLayer, 'getRoots', {
providesTags: [{ type: 'Roots', id: 'LIST' }],
}),

getRootHistory: query(build, DataLayer, 'getRootHistory', {
providesTags: (_result, _error, { id }) => [{ type: 'RootHistories', id }],
}),

getSyncStatus: query(build, DataLayer, 'getSyncStatus', {
providesTags: (_result, _error, { id }) => [{ type: 'SyncStatus', id }],
}),

getValue: query(build, DataLayer, 'getValue', {
providesTags: (_result, _error, { id, key }) => [{ type: 'Values', id: id + key }],
}),

insert: mutation(build, DataLayer, 'insert', {
invalidatesTags: (_result, _error, { id }) => [
{ type: 'Offers', id: 'LIST' },
{ type: 'Offers', id },
],
}),

makeOffer: mutation(build, DataLayer, 'makeOffer', {
invalidatesTags: [{ type: 'Offers', id: 'LIST' }],
}),

removeSubscriptions: mutation(build, DataLayer, 'removeSubscriptions', {
invalidatesTags: (_result, _error, { id }) => [
{ type: 'Subscriptions', id: 'LIST' },
{ type: 'Subscriptions', id },
],
}),

subscribe: mutation(build, DataLayer, 'subscribe', {
invalidatesTags: (_result, _error, { id }) => [
{ type: 'Subscriptions', id: 'LIST' },
{ type: 'Subscriptions', id },
],
}),

subscriptions: query(build, DataLayer, 'subscriptions', {
providesTags: [{ type: 'Subscriptions' }],
}),

takeOffer: mutation(build, DataLayer, 'takeOffer', {
invalidatesTags: [{ type: 'Offers', id: 'LIST' }],
}),

unsubscribe: mutation(build, DataLayer, 'unsubscribe', {
invalidatesTags: (_result, _error, { id }) => [
{ type: 'Subscriptions', id: 'LIST' },
{ type: 'Subscriptions', id },
],
}),

verifyOffer: query(build, DataLayer, 'verifyOffer', {
providesTags: [{ type: 'Offers' }],
}),
}),
});

export const {
useAddMirrorMutation,
useAddMissingFilesMutation,
useBatchUpdateMutation,
useCancelOfferMutation,
useCheckPluginsQuery,
useClearPendingRootsMutation,
useCreateDataStoreMutation,
useDeleteKeyMutation,
useDeleteMirrorMutation,
useGetAncestorsQuery,
useGetKeysQuery,
useGetKeysValuesQuery,
useGetKvDiffQuery,
useGetLocalRootQuery,
useGetMirrorsQuery,
useGetOwnedStoresQuery,
useGetRootQuery,
useGetRootsQuery,
useGetRootHistoryQuery,
useGetSyncStatusQuery,
useGetValueQuery,
useInsertMutation,
useMakeOfferMutation,
useRemoveSubscriptionsMutation,
useSubscribeMutation,
useSubscriptionsQuery,
useTakeOfferMutation,
useUnsubscribeMutation,
useVerifyOfferQuery,
} = dataLayerApi;
9 changes: 8 additions & 1 deletion packages/api-react/src/services/fullNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import api, { baseQuery } from '../api';
import onCacheEntryAddedInvalidate from '../utils/onCacheEntryAddedInvalidate';
import { query, mutation } from '../utils/reduxToolkitEndpointAbstractions';

const apiWithTag = api.enhanceEndpoints({ addTagTypes: ['BlockchainState', 'FeeEstimate', 'FullNodeConnections'] });
const apiWithTag = api.enhanceEndpoints({
addTagTypes: ['BlockchainState', 'FeeEstimate', 'FullNodeConnections', 'Transactions'],
});

// // Examples with levels of abstraction
// export const myTestApi = apiWithTag.injectEndpoints({
Expand Down Expand Up @@ -142,6 +144,10 @@ export const fullNodeApi = apiWithTag.injectEndpoints({
getFeeEstimate: query(build, FullNode, 'getFeeEstimate', {
providesTags: [{ type: 'FeeEstimate' }],
}),

pushTx: mutation(build, FullNode, 'pushTx', {
invalidatesTags: [{ type: 'Transactions', id: 'LIST' }],
}),
}),
});

Expand All @@ -156,4 +162,5 @@ export const {
useGetBlockQuery,
useGetBlockRecordQuery,
useGetFeeEstimateQuery,
usePushTxMutation,
} = fullNodeApi;
38 changes: 38 additions & 0 deletions packages/api-react/src/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as client from './client';
import * as daemon from './daemon';
import * as dataLayer from './dataLayer';
import * as farmer from './farmer';
import * as fullNode from './fullNode';
import * as harvester from './harvester';
Expand Down Expand Up @@ -43,6 +44,39 @@ export const {
useGetPublicKeyQuery,
} = daemon;

export const {
dataLayerApi,

useAddMirrorMutation,
useAddMissingFilesMutation,
useBatchUpdateMutation,
useCheckPluginsQuery,
useClearPendingRootsMutation,
useCreateDataStoreMutation,
useDeleteKeyMutation: useDeleteDataLayerKeyMutation,
useDeleteMirrorMutation,
useGetAncestorsQuery,
useGetKeysQuery: useGetDataLayerKeysQuery,
useGetKeysValuesQuery,
useGetKvDiffQuery,
useGetLocalRootQuery,
useGetMirrorsQuery,
useGetOwnedStoresQuery,
useGetRootQuery,
useGetRootsQuery,
useGetRootHistoryQuery,
useGetSyncStatusQuery: useGetDataLayerSyncStatusQuery,
useGetValueQuery,
useInsertMutation,
useMakeOfferMutation,
useRemoveSubscriptionsMutation,
useSubscribeMutation,
useSubscriptionsQuery,
useTakeOfferMutation: useTakeDataLayerOfferMutation,
useUnsubscribeMutation,
useVerifyOfferQuery,
} = dataLayer;

// farmer hooks
export const {
farmerApi,
Expand Down Expand Up @@ -86,6 +120,7 @@ export const {
useGetBlockQuery,
useGetBlockRecordQuery,
useGetFeeEstimateQuery,
usePushTxMutation,
} = fullNode;

// wallet hooks
Expand Down Expand Up @@ -167,6 +202,8 @@ export const {
useGetDIDNameQuery,
useSetDIDNameMutation,
useGetDIDRecoveryListQuery,
useGetDIDMetadataQuery,
useUpdateDIDMetadataMutation,
useGetDIDInformationNeededForRecoveryQuery,
useGetDIDCurrentCoinInfoQuery,
useGetDIDInfoQuery,
Expand All @@ -181,6 +218,7 @@ export const {
useGetNFTWalletsWithDIDsQuery,
useGetNFTInfoQuery,
useLazyGetNFTInfoQuery,
useMintBulkMutation,
useMintNFTMutation,
useTransferNFTMutation,
useSetNFTDIDMutation,
Expand Down
32 changes: 31 additions & 1 deletion packages/api-react/src/services/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const tagTypes = [
'DID',
'DIDCoinInfo',
'DIDInfo',
'DIDMetadata',
'DIDName',
'DIDPubKey',
'DIDRecoveryInfo',
Expand Down Expand Up @@ -1132,7 +1133,28 @@ export const walletApi = apiWithTag.injectEndpoints({
}),

getDIDInfo: query(build, DID, 'getDidInfo', {
providesTags: (result, _error, { coinOrDIDId }) => (result ? [{ type: 'DIDInfo', id: coinOrDIDId }] : []),
providesTags: (result, _error, { coinId }) => (result ? [{ type: 'DIDInfo', id: coinId }] : []),
}),

// findLostDID: mutation(build, DID, 'findLostDID', {
// invalidatesTags: (_result, _error, { coinId }) => [
// { type: 'DIDInfo', id: coinId },
// { type: 'DIDCoinInfo', id: coinId },
// ],
// }),

getDIDMetadata: query(build, DID, 'getDidMetadata', {
providesTags: (result, _error, { walletId }) => (result ? [{ type: 'DIDMetadata', id: walletId }] : []),
}),

updateDIDMetadata: mutation(build, DID, 'updateDidMetadata', {
invalidatesTags: (_result, _error, { walletId }) => [
{ type: 'DIDInfo' },
{ type: 'DIDCoinInfo', id: walletId },
{ type: 'Wallets', id: walletId },
{ type: 'DIDWallet', id: walletId },
{ type: 'DIDMetadata', id: walletId },
],
}),

// createDIDBackup: did_create_backup_file needs an RPC change (remove filename param, return file contents)
Expand Down Expand Up @@ -1354,6 +1376,10 @@ export const walletApi = apiWithTag.injectEndpoints({
providesTags: (result, _error) => (result ? [{ type: 'NFTInfo', id: result.launcherId }] : []),
}),

mintBulk: mutation(build, NFT, 'mintBulk', {
invalidatesTags: (result, _error) => (result ? [{ type: 'NFTInfo', id: 'LIST' }] : []),
}),

mintNFT: mutation(build, NFT, 'mintNFT', {
invalidatesTags: (result, _error) => (result ? [{ type: 'NFTInfo', id: 'LIST' }] : []),
}),
Expand Down Expand Up @@ -1527,6 +1553,9 @@ export const {
useGetDIDPubKeyQuery,
useGetDIDQuery,
useGetDIDsQuery,
useGetDIDMetadataQuery,
useUpdateDIDMetadataMutation,
// useFindLostDIDMutation,
useGetDIDNameQuery,
useSetDIDNameMutation,
useGetDIDRecoveryListQuery,
Expand All @@ -1544,6 +1573,7 @@ export const {
useGetNFTWalletsWithDIDsQuery,
useGetNFTInfoQuery,
useLazyGetNFTInfoQuery,
useMintBulkMutation,
useMintNFTMutation,
useTransferNFTMutation,
useSetNFTDIDMutation,
Expand Down
5 changes: 5 additions & 0 deletions packages/api/src/@types/DataLayerChange.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface DataLayerChange {
action: 'delete' | 'insert';
key: string;
value?: string;
}
8 changes: 8 additions & 0 deletions packages/api/src/@types/DataLayerRootHash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type DataLayerRootHash = {
confirmed: boolean;
hash: string;
id: string;
timestamp: number;
};

export default DataLayerRootHash;
Loading

0 comments on commit b9b26fd

Please sign in to comment.