mirror of https://gitlab.com/ecentrics/concordia
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.5 KiB
51 lines
1.5 KiB
4 years ago
|
import unirest from 'unirest';
|
||
|
import {
|
||
|
contractsProviderHost,
|
||
|
contractsProviderPort,
|
||
|
contractsVersionHash,
|
||
|
} from 'concordia-shared/src/environment/interpolated/contractsProvider';
|
||
|
import { pinnerApiHost, pinnerApiPort } from 'concordia-shared/src/environment/interpolated/pinner';
|
||
|
import { FORUM_CONTRACT } from 'concordia-shared/src/constants/contracts/ContractNames';
|
||
|
|
||
|
function getContractsDownloadRequest() {
|
||
|
const HOST = pinnerApiHost;
|
||
|
const PORT = pinnerApiPort;
|
||
|
|
||
|
return unirest(
|
||
|
'GET',
|
||
|
`http://${contractsProviderHost}:${contractsProviderPort}/contracts/${contractsVersionHash}`,
|
||
|
).headers({
|
||
|
'Access-Control-Allow-Origin': `${HOST}:${PORT}`,
|
||
|
'Access-Control-Allow-Credentials': 'true',
|
||
|
});
|
||
|
}
|
||
|
|
||
|
const validateRemoteContracts = (remoteContracts) => {
|
||
|
if (!remoteContracts
|
||
|
.map((remoteContract) => remoteContract.contractName)
|
||
|
.includes(FORUM_CONTRACT)) {
|
||
|
throw new Error('Forum contract is missing from artifacts.');
|
||
|
}
|
||
|
};
|
||
|
|
||
|
const downloadContractArtifacts = () => {
|
||
|
const request = getContractsDownloadRequest();
|
||
|
|
||
|
return new Promise((resolve, reject) => request
|
||
|
.end((response) => {
|
||
|
if (response.error) {
|
||
|
reject(new Error(`Remote contract artifacts download request failed!\n${response.error}`));
|
||
|
}
|
||
|
|
||
|
resolve(response.raw_body);
|
||
|
})).then((contractsRawData) => {
|
||
|
const remoteContracts = JSON.parse(contractsRawData);
|
||
|
|
||
|
validateRemoteContracts(remoteContracts);
|
||
|
|
||
|
return remoteContracts;
|
||
|
});
|
||
|
};
|
||
|
|
||
|
export default downloadContractArtifacts;
|