Skip to content

Commit

Permalink
Checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiaMineJP committed Oct 29, 2024
1 parent 2359fa9 commit 00cd67b
Show file tree
Hide file tree
Showing 8 changed files with 251 additions and 72 deletions.
7 changes: 4 additions & 3 deletions packages/api-react/src/services/dataLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const apiWithTag = api.enhanceEndpoints({
'StoreMirrors',
'PendingRoots',
'Plugins',
'Files',
],
});
export const dataLayerApi = apiWithTag.injectEndpoints({
Expand All @@ -33,7 +34,7 @@ export const dataLayerApi = apiWithTag.injectEndpoints({
}),

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

batchUpdate: mutation(build, DataLayer, 'batchUpdate', {
Expand All @@ -44,15 +45,15 @@ export const dataLayerApi = apiWithTag.injectEndpoints({
}),

cancelOffer: mutation(build, DataLayer, 'cancelOffer', {
invalidatesTags: (_result, _error, { tradeId }) => [{ type: 'Offers', tradeId }],
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', storeId }],
invalidatesTags: (_result, _error, { storeId }) => [{ type: 'PendingRoots', id: storeId }],
}),

createDataStore: mutation(build, DataLayer, 'createDataStore', {
Expand Down
4 changes: 3 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
3 changes: 3 additions & 0 deletions packages/api-react/src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export const {
useGetBlockQuery,
useGetBlockRecordQuery,
useGetFeeEstimateQuery,
usePushTxMutation,
} = fullNode;

// wallet hooks
Expand Down Expand Up @@ -201,6 +202,7 @@ export const {
useGetDIDNameQuery,
useSetDIDNameMutation,
useGetDIDRecoveryListQuery,
useGetDIDMetadataQuery,
useUpdateDIDMetadataMutation,
useGetDIDInformationNeededForRecoveryQuery,
useGetDIDCurrentCoinInfoQuery,
Expand All @@ -216,6 +218,7 @@ export const {
useGetNFTWalletsWithDIDsQuery,
useGetNFTInfoQuery,
useLazyGetNFTInfoQuery,
useMintBulkMutation,
useMintNFTMutation,
useTransferNFTMutation,
useSetNFTDIDMutation,
Expand Down
4 changes: 3 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 @@ -1148,10 +1149,11 @@ export const walletApi = apiWithTag.injectEndpoints({

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

Expand Down
211 changes: 172 additions & 39 deletions packages/api/src/services/DataLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,96 +10,208 @@ export default class DataLayer extends Service {
super(ServiceName.DATALAYER, client, options);
}

async addMirror(args: { id: string; urls: string[]; amount: number; fee: number }) {
async addMirror(args: { id: string; urls: string[]; amount: number; fee?: number }) {
return this.command<{}>('add_mirror', args);
}

async addMissingFiles(args: { ids: string[]; override: boolean; folderName: string }) {
async addMissingFiles(args: { ids?: string[]; override?: boolean; foldername?: string }) {
return this.command<{}>('add_missing_files', args);
}

async batchUpdate(args: { id: string; changeList: DataLayerChange[]; fee: number }) {
return this.command<{}>('batch_update', args);
async batchUpdate(args: { id: string; changelist: DataLayerChange[]; fee?: number; submitOnChain?: boolean }) {
return this.command<{ txId?: string }>('batch_update', args);
}

async cancelOffer(args: { tradeId: string; secure: boolean; fee: number }) {
return this.command<{}>('cancel_offer', args);
async cancelOffer(args: { tradeId: string; secure: boolean; fee?: number }) {
return this.command<{ success: boolean }>('cancel_offer', args);
}

async checkPlugins(args: {}) {
return this.command<{}>('check_plugins', args);
return this.command<{
pluginStatus: {
uploaders: Record<string, any>;
downloaders: Record<string, any>;
};
}>('check_plugins', args);
}

async clearPendingRoots(args: { storeId: string }) {
return this.command<{}>('clear_pending_roots', args);
return this.command<{
success: boolean;
root:
| {
treeId: string;
nodeHash: string | undefined;
generation: number;
status: number;
}
| undefined;
}>('clear_pending_roots', args);
}

async createDataStore(args: { fee: number }) {
return this.command<{}>('create_data_store', args);
async createDataStore(args: { fee?: number; verbose?: boolean }) {
return this.command<{ txs?: any[]; id: string }>('create_data_store', args);
}

async deleteKey(args: { id: string; key: string; fee: number }) {
return this.command<{}>('delete_key', args);
async deleteKey(args: { id: string; key: string; fee?: number }) {
return this.command<{ txId: string }>('delete_key', args);
}

async deleteMirror(args: { id: string; fee: number }) {
async deleteMirror(args: { coinId: string; fee?: number }) {
return this.command<{}>('delete_mirror', args);
}

async getAncestors(args: { id: string; hash: string }) {
return this.command<{}>('get_ancestors', args);
return this.command<{
ancestors: Array<{
hash: string;
leftHash: string;
rightHash: string;
}>;
}>('get_ancestors', args);
}

async getKeys(args: { id: string; rootHash: string }) {
return this.command<{}>('get_keys', args);
async getKeys(args: { id: string; rootHash?: string; page?: number; maxPageSize?: number }) {
return this.command<
| {
keys: string[];
}
| {
keys: string[];
totalPages: number;
totalBytes: number;
rootHash: string | undefined;
}
>('get_keys', args);
}

async getKeysValues(args: { id: string; rootHash: string }) {
return this.command<{}>('get_keys_values', args);
async getKeysValues(args: { id: string; rootHash?: string; page?: number; maxPageSize?: number }) {
return this.command<
| {
keysValues: Array<{
hash: string;
key: string;
value: string;
}>;
}
| {
keysValues: Array<{
hash: string;
key: string;
value: string;
}>;
totalPages: number;
totalBytes: number;
rootHash: string | undefined;
}
>('get_keys_values', args);
}

async getKvDiff(args: { id: string; hash1: string; hash2: string }) {
return this.command<{}>('get_kv_diff', args);
async getKvDiff(args: { id: string; hash1: string; hash2: string; page?: number; maxPageSize?: number }) {
return this.command<
| {
diff: Array<{
type: string;
key: string;
value: string;
}>;
}
| {
diff: Array<{
type: string;
key: string;
value: string;
}>;
totalPages: number;
totalBytes: number;
}
>('get_kv_diff', args);
}

async getLocalRoot(args: { id: string }) {
return this.command<{}>('get_local_root', args);
return this.command<{ hash: string | undefined }>('get_local_root', args);
}

async getMirrors(args: { id: string }) {
return this.command<{}>('get_mirrors', args);
return this.command<{
mirrors: Array<{
coinId: string;
launcherId: string;
amount: number;
urls: string[];
ours: boolean;
}>;
}>('get_mirrors', args);
}

async getOwnedStores(args: {}) {
return this.command<{ storeIds: string[]; success: boolean }>('get_owned_stores', args);
}

async getRoot(args: { id: string }) {
return this.command<{}>('get_root', args);
return this.command<{
hash: string;
confirmed: boolean;
timestamp: number;
}>('get_root', args);
}

async getRoots(args: { ids: string[] }) {
return this.command<{}>('get_roots', args);
return this.command<{
rootHashes: Array<{
id: string;
hash: string;
confirmed: boolean;
timestamp: number;
}>;
}>('get_roots', args);
}

async getRootHistory(args: { id: string }) {
return this.command<{}>('get_root_history', args);
return this.command<{
rootHistory: Array<{
rootHash: string;
confirmed: boolean;
timestamp: number;
}>;
}>('get_root_history', args);
}

async getSyncStatus(args: { id: string }) {
return this.command<{}>('get_sync_status', args);
return this.command<{
syncStatus: {
rootHash: string;
generation: number;
targetRootHash: string;
targetGeneration: number;
};
}>('get_sync_status', args);
}

async getValue(args: { id: string; key: string; rootHash: string }) {
return this.command<{}>('get_value', args);
async getValue(args: { id: string; key: string; rootHash?: string }) {
return this.command<{
value: string | undefined;
}>('get_value', args);
}

async insert(args: { id: string; key: string; value: string; fee: number }) {
return this.command<{}>('insert', args);
async insert(args: { id: string; key: string; value: string; fee?: number }) {
return this.command<{ txId: string }>('insert', args);
}

async makeOffer(args: { maker: string; fee: number }) {
return this.command<{}>('make_offer', args);
async makeOffer(args: {
maker: { storeId: string; inclusions: Array<{ key: string; value: string }> };
taker: { storeId: string; inclusions: Array<{ key: string; value: string }> };
fee?: number;
}) {
return this.command<{
success: boolean;
offer: {
tradeId: string;
offer: string;
taker: { storeId: string; inclusions: Array<{ key: string; value: string }> };
maker: { storeId: string; inclusions: Array<{ key: string; value: string }> };
};
}>('make_offer', args);
}

async removeSubscriptions(args: { id: string; urls: string[] }) {
Expand All @@ -110,23 +222,44 @@ export default class DataLayer extends Service {
return this.command<{}>('subscribe', args);
}

async subscriptions(args: {}) {
async subscriptions(args: { id: string; urls: string[] }) {
return this.command<{}>('subscriptions', args);
}

async takeOffer(args: { offer: string; fee: number }) {
return this.command<{}>('take_offer', args);
async takeOffer(args: {
offer: {
tradeId: string;
offer: string;
taker: { storeId: string; inclusions: Array<{ key: string; value: string }> };
maker: { storeId: string; inclusions: Array<{ key: string; value: string }> };
};
fee?: number;
}) {
return this.command<{ success: boolean; tradeId: string }>('take_offer', args);
}

async unsubscribe(args: { id: string }) {
async unsubscribe(args: { id: string; retain?: boolean }) {
return this.command<{}>('unsubscribe', args);
}

async verifyOffer(args: { offer: string }) {
return this.command<{}>('verify_offer', args);
async verifyOffer(args: {
offer: {
tradeId: string;
offer: string;
taker: { storeId: string; inclusions: Array<{ key: string; value: string }> };
maker: { storeId: string; inclusions: Array<{ key: string; value: string }> };
};
fee?: number;
}) {
return this.command<{
success: boolean;
valid: boolean;
error: string | undefined;
fee: number | undefined;
}>('verify_offer', args);
}

async walletLogIn(args: { fingerprint: string }) {
async walletLogIn(args: { fingerprint: number }) {
return this.command<{}>('wallet_log_in', args);
}
}
2 changes: 1 addition & 1 deletion packages/api/src/services/FullNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default class FullNode extends Service {
}

async pushTx(args: { spendBundle: SpendBundle }) {
return this.command<void>('push_tx', args);
return this.command<{ status: string }>('push_tx', args);
}

onBlockchainState(callback: (data: any, message: Message) => void, processData?: (data: any) => any) {
Expand Down
Loading

0 comments on commit 00cd67b

Please sign in to comment.