Skip to content

Commit

Permalink
feat: automatically add mirror when subscribing to store
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Aug 16, 2022
1 parent 3c430d2 commit 9eb29f3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/datalayer/persistance.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import request from 'request-promise';
import os from 'os';
import { getConfig } from '../utils/config-loader';
import { decodeHex } from '../utils/datalayer-utils';
import fullNode from './fullNode';
import { publicIpv4 } from 'public-ip';

import { logger } from '../config/logger.cjs';

Expand Down Expand Up @@ -259,6 +261,13 @@ export const subscribeToStoreOnDataLayer = async (storeId) => {

if (Object.keys(data).includes('success') && data.success) {
logger.info(`Successfully Subscribed: ${storeId}`);

const chiaConfig = fullNode.getChiaConfig();
await addMirror(
storeId,
`http://${await publicIpv4()}:${chiaConfig.data_layer.host_port}`,
);

return data;
}

Expand Down Expand Up @@ -321,7 +330,7 @@ export const getRootDiff = async (storeId, root1, root2) => {
}
};

export const addMirror = async (storeId, url) => {
const _addMirror = async (storeId, url) => {
const options = {
url: `${rpcUrl}/add_mirror`,
body: JSON.stringify({
Expand Down Expand Up @@ -349,3 +358,5 @@ export const addMirror = async (storeId, url) => {
return false;
}
};

export const addMirror = _addMirror;
1 change: 1 addition & 0 deletions src/datalayer/syncService.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ const getSubscribedStoreData = async (

if (!alreadySubscribed) {
const response = await subscribeToStoreOnDataLayer(storeId);

if (!response || !response.success) {
if (!response) {
logger.debug(
Expand Down
1 change: 1 addition & 0 deletions src/datalayer/writeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const createDataLayerStore = async () => {
`Created storeId: ${storeId}, waiting for this to be confirmed on the blockchain.`,
);
await waitForStoreToBeConfirmed(storeId);

const chiaConfig = fullNode.getChiaConfig();
await dataLayer.addMirror(
storeId,
Expand Down

0 comments on commit 9eb29f3

Please sign in to comment.