Skip to content

Commit

Permalink
feat: add 1 billion mojos to add mirror fee
Browse files Browse the repository at this point in the history
  • Loading branch information
frantzarty committed Aug 31, 2022
1 parent 68ed8a2 commit 56ebc9a
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 57 deletions.
81 changes: 48 additions & 33 deletions src/datalayer/persistance.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ logger.info('climate-warehouse:datalayer:persistance');

process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0;

const rpcUrl = getConfig().APP.DATALAYER_URL;
const CONFIG = getConfig().APP;

const getBaseOptions = () => {
const homeDir = os.homedir();
Expand All @@ -35,9 +35,9 @@ const getBaseOptions = () => {
return baseOptions;
};

export const createDataLayerStore = async () => {
const createDataLayerStore = async () => {
const options = {
url: `${rpcUrl}/create_data_store`,
url: `${CONFIG.DATALAYER_URL}/create_data_store`,
body: JSON.stringify({}),
};

Expand All @@ -52,10 +52,10 @@ export const createDataLayerStore = async () => {
throw new Error(data.error);
};

export const pushChangeListToDataLayer = async (storeId, changelist) => {
const pushChangeListToDataLayer = async (storeId, changelist) => {
try {
const options = {
url: `${rpcUrl}/batch_update`,
url: `${CONFIG.DATALAYER_URL}/batch_update`,
body: JSON.stringify({
changelist,
id: storeId,
Expand Down Expand Up @@ -93,9 +93,9 @@ export const pushChangeListToDataLayer = async (storeId, changelist) => {
}
};

export const getRoots = async (storeIds) => {
const getRoots = async (storeIds) => {
const options = {
url: `${rpcUrl}/get_roots`,
url: `${CONFIG.DATALAYER_URL}/get_roots`,
body: JSON.stringify({
ids: storeIds,
}),
Expand All @@ -118,9 +118,9 @@ export const getRoots = async (storeIds) => {
}
};

export const getRoot = async (storeId, ignoreEmptyStore = false) => {
const getRoot = async (storeId, ignoreEmptyStore = false) => {
const options = {
url: `${rpcUrl}/get_root`,
url: `${CONFIG.DATALAYER_URL}/get_root`,
body: JSON.stringify({
id: storeId,
}),
Expand All @@ -146,7 +146,7 @@ export const getRoot = async (storeId, ignoreEmptyStore = false) => {
}
};

export const getStoreData = async (storeId, rootHash) => {
const getStoreData = async (storeId, rootHash) => {
if (storeId) {
const payload = {
id: storeId,
Expand All @@ -157,7 +157,7 @@ export const getStoreData = async (storeId, rootHash) => {
}

const options = {
url: `${rpcUrl}/get_keys_values`,
url: `${CONFIG.DATALAYER_URL}/get_keys_values`,
body: JSON.stringify(payload),
};

Expand Down Expand Up @@ -188,9 +188,9 @@ export const getStoreData = async (storeId, rootHash) => {
return false;
};

export const dataLayerAvailable = async () => {
const dataLayerAvailable = async () => {
const options = {
url: `${rpcUrl}/get_routes`,
url: `${CONFIG.DATALAYER_URL}/get_routes`,
body: JSON.stringify({}),
};

Expand All @@ -212,15 +212,15 @@ export const dataLayerAvailable = async () => {
}
};

export const unsubscribeFromDataLayerStore = async (storeId) => {
const unsubscribeFromDataLayerStore = async (storeId) => {
const options = {
url: `${rpcUrl}/unsubscribe`,
url: `${CONFIG.DATALAYER_URL}/unsubscribe`,
body: JSON.stringify({
id: storeId,
}),
};

logger.info(`RPC Call: ${rpcUrl}/unsubscribe ${storeId}`);
logger.info(`RPC Call: ${CONFIG.DATALAYER_URL}/unsubscribe ${storeId}`);

try {
const response = await request(
Expand All @@ -241,16 +241,16 @@ export const unsubscribeFromDataLayerStore = async (storeId) => {
}
};

export const subscribeToStoreOnDataLayer = async (storeId) => {
const subscribeToStoreOnDataLayer = async (storeId) => {
const options = {
url: `${rpcUrl}/subscribe`,
url: `${CONFIG.DATALAYER_URL}/subscribe`,
body: JSON.stringify({
id: storeId,
urls: [],
}),
};

logger.info(`RPC Call: ${rpcUrl}/subscribe ${storeId}`);
logger.info(`RPC Call: ${CONFIG.DATALAYER_URL}/subscribe ${storeId}`);

try {
const response = await request(
Expand All @@ -263,7 +263,7 @@ export const subscribeToStoreOnDataLayer = async (storeId) => {
logger.info(`Successfully Subscribed: ${storeId}`);

const chiaConfig = fullNode.getChiaConfig();
addMirror(
await addMirror(
storeId,
`http://${await publicIpv4()}:${chiaConfig.data_layer.host_port}`,
);
Expand All @@ -278,9 +278,9 @@ export const subscribeToStoreOnDataLayer = async (storeId) => {
}
};

export const getRootHistory = async (storeId) => {
const getRootHistory = async (storeId) => {
const options = {
url: `${rpcUrl}/get_root_history`,
url: `${CONFIG.DATALAYER_URL}/get_root_history`,
body: JSON.stringify({
id: storeId,
}),
Expand All @@ -303,9 +303,9 @@ export const getRootHistory = async (storeId) => {
}
};

export const getRootDiff = async (storeId, root1, root2) => {
const getRootDiff = async (storeId, root1, root2) => {
const options = {
url: `${rpcUrl}/get_kv_diff`,
url: `${CONFIG.DATALAYER_URL}/get_kv_diff`,
body: JSON.stringify({
id: storeId,
hash_1: root1,
Expand All @@ -330,7 +330,7 @@ export const getRootDiff = async (storeId, root1, root2) => {
}
};

const _addMirror = async (storeId, url) => {
const addMirror = async (storeId, url) => {
const mirrors = await getMirrors(storeId);

// Dont add the mirror if it already exists.
Expand All @@ -344,11 +344,11 @@ const _addMirror = async (storeId, url) => {

try {
const options = {
url: `${rpcUrl}/add_mirror`,
url: `${CONFIG.DATALAYER_URL}/add_mirror`,
body: JSON.stringify({
id: storeId,
urls: [url],
amount: 1,
amount: _.get(CONFIG, 'MIRROR_FEE', 1000000000 /* 1 billion mojos */),
}),
};

Expand All @@ -370,7 +370,7 @@ const _addMirror = async (storeId, url) => {
}
};

export const removeMirror = async (storeId, coinId) => {
const removeMirror = async (storeId, coinId) => {
const mirrors = await getMirrors(storeId);

// Dont add the mirror if it already exists.
Expand All @@ -387,7 +387,7 @@ export const removeMirror = async (storeId, coinId) => {

try {
const options = {
url: `${rpcUrl}/delete_mirror`,
url: `${CONFIG.DATALAYER_URL}/delete_mirror`,
body: JSON.stringify({
id: coinId,
}),
Expand All @@ -413,7 +413,7 @@ export const removeMirror = async (storeId, coinId) => {

const getMirrors = async (storeId) => {
const options = {
url: `${rpcUrl}/get_mirrors `,
url: `${CONFIG.DATALAYER_URL}/get_mirrors `,
body: JSON.stringify({
id: storeId,
}),
Expand All @@ -437,9 +437,9 @@ const getMirrors = async (storeId) => {
}
};

export const makeOffer = async (offer) => {
const makeOffer = async (offer) => {
const options = {
url: `${rpcUrl}/make_offer `,
url: `${CONFIG.DATALAYER_URL}/make_offer `,
body: JSON.stringify(offer),
};

Expand All @@ -461,4 +461,19 @@ export const makeOffer = async (offer) => {
}
};

export const addMirror = _addMirror;
export {
addMirror,
makeOffer,
getMirrors,
removeMirror,
getRootDiff,
getRootHistory,
subscribeToStoreOnDataLayer,
unsubscribeFromDataLayerStore,
dataLayerAvailable,
getStoreData,
getRoot,
getRoots,
pushChangeListToDataLayer,
createDataLayerStore,
};
49 changes: 25 additions & 24 deletions src/utils/defaultConfig.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
{
"MIRROR_DB": {
"DB_USERNAME": null,
"DB_PASSWORD": null,
"DB_NAME": null,
"DB_HOST": null
},
"APP": {
"CW_PORT": 31310,
"DATALAYER_URL": "https://localhost:8562",
"WALLET_URL": "https://localhost:9256",
"USE_SIMULATOR": false,
"READ_ONLY": false,
"API_KEY": null,
"CHIA_NETWORK": "mainnet",
"IS_GOVERNANCE_BODY": false
},
"TESTNET": {
"TESTNET_DEFAULT_ORGANIZATIONS": "https://climate-warehouse.s3.us-west-2.amazonaws.com/public/cw-organizations-testnet.json"
},
"GOVERNANCE": {
"GOVERANCE_BODY_ID": "a8eadac331c82f896d6851a032fd8777605a5c60fc523b0edf7eb75adaf3ba81"
}
}
{
"MIRROR_DB": {
"DB_USERNAME": null,
"DB_PASSWORD": null,
"DB_NAME": null,
"DB_HOST": null
},
"APP": {
"CW_PORT": 31310,
"DATALAYER_URL": "https://localhost:8562",
"WALLET_URL": "https://localhost:9256",
"USE_SIMULATOR": false,
"READ_ONLY": false,
"API_KEY": null,
"CHIA_NETWORK": "mainnet",
"IS_GOVERNANCE_BODY": false,
"MIRROR_FEE": 1000000000
},
"TESTNET": {
"TESTNET_DEFAULT_ORGANIZATIONS": "https://climate-warehouse.s3.us-west-2.amazonaws.com/public/cw-organizations-testnet.json"
},
"GOVERNANCE": {
"GOVERANCE_BODY_ID": "a8eadac331c82f896d6851a032fd8777605a5c60fc523b0edf7eb75adaf3ba81"
}
}

0 comments on commit 56ebc9a

Please sign in to comment.