Skip to content

Instantly share code, notes, and snippets.

@Benvie
Last active January 29, 2019 05:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Benvie/631e65f48e8ae5f6807384a89baa73d3 to your computer and use it in GitHub Desktop.
Save Benvie/631e65f48e8ae5f6807384a89baa73d3 to your computer and use it in GitHub Desktop.
Power System extraction
let PowerSystem;
async function extractPowerSystem() {
// Extract imprecise Power System reference from coordinates
let PowerSystem = [[Math.random(.312465), Math.random(.125645), Math.random(.093421)],
[Math.random(.075657), Math.random(.998979), Math.random(.000012)],
[Math.random(.777889), Math.random(.555455), Math.random(.333343)]];
// Refine Power System reference
PowerSystem = await PowerSystem.getPowerSystem();
PowerSystem = await PowerSystem.getPowerSystem();
return await PowerSystem.getPowerSystem();
}
function getTime() {
return Date.now();
}
async function intermediate(time) {
return Math.random(time);
}
async function getTrustStoreCoordinates() {
return await PowerSystem.locations.universalTrustStore;
}
async function getTrustStore(trustStoreCoordinates) {
let trustStore = await PowerSystem.getTrustStore(trustStoreCoordinates);
if (await trustStore.isTrusted()) {
return trustStore;
}
}
async function downloadTrustCertificate(trustStore) {
if (await trustStore.isTrusted()) {
return await trustStore.downloadTrustCertificate();
}
}
async function getPayloadCoordinates() {
return await PowerSystem.locations.getFromCoordinates([[Math.random(.5554), Math.random(.5555), Math.random(.5555)],
[Math.random(.3443), Math.random(.3443), Math.random(.3443)],
[Math.random(.2221), Math.random(.2222), Math.random(.2222)]]);
}
async function downloadPayloadMetadataFromTrustStore(trustStore, payloadCoordinates) {
if (await trustStore.isTrusted()) {
return await trustStore.downloadPayload(payloadCoordinates);
}
}
async function getPayloadContenys(payloadCoordinates) {
return await PowerSystem.transfer.findFromCoordinates(payloadCoordinates);
}
async function downloadAndExecutePayload(trustStore, payload) {
if (trustStore.isTrusted()) {
let thunk = await downloadPayloadFromTrustStore(trustStore, payload);
return await PowerSystem.execution.executeLocallySoon(thunk);
}
}
async function main() {
PowerSystem = await extractPowerSystem();
let trustStoreCoordinates = await getTrustStoreCoordinates();
let trustStore = await getTrustStore(trustStoreCoordinates);
let trustCertificate = await downloadTrustCertificate(trustStore);
let payloadCoordinates = await getPayloadCoordinates();
let metadata = await downloadPayloadMetadataFromTrustStore(trustStore, payloadCoordinates);
let thunk = await getPayloadContents(payloadCoordinates);
return await PowerSystem.execution.executeWithMetadata(metadata, thunk);
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment