Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPIKE: Move API Code Logic to Separate Handlers #70

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions bases/shared/instagoric-server/api/faucet-app/homeHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// @ts-check
import { getDenoms } from '../../utils.js';
import { AG0_MODE, COMMANDS } from '../../constants.js';

export async function homeRoute(req, res) {
const denoms = await getDenoms();
let denomHtml = '';
denoms.forEach(denom => {
denomHtml += `<label><input type="checkbox" name="denoms" value=${denom}> ${denom} </label>`;
});
const denomsDropDownHtml = `<div class="dropdown"> <div class="dropdown-content"> ${denomHtml}</div> </div>`;

const clientText = !AG0_MODE
? `<input type="radio" id="client" name="command" value=${COMMANDS['SEND_AND_PROVISION_IST']} onclick="toggleRadio(event)">
<label for="client">send IST and provision </label>
<select name="clientType">
<option value="SMART_WALLET">smart wallet</option>
<option value="REMOTE_WALLET">ag-solo</option>
</select>`
: '';
res.send(
`<html><head><title>Faucet</title>
<script>
function toggleRadio(event) {
var field = document.getElementById('denoms');

if (event.target.value === "${COMMANDS['CUSTOM_DENOMS_LIST']}") {
field.style.display = 'block';
} else if (field.style.display === 'block') {
field.style.display = 'none';
}
}
</script>

<style>

.dropdown {
overflow: scroll;
height: 120px;
width: fit-content;
}

.dropdown-content {
display: block;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}

.dropdown-content label {
display: block;
margin-top: 10px;
}

.denomsClass {
display: none;
}
</style>
</head><body><h1>welcome to the faucet</h1>
<form action="/go" method="post">
<label for="address">Address:</label> <input id="address" name="address" type="text" /><br>
Request: <input type="radio" id="delegate" name="command" value=${COMMANDS['SEND_BLD/IBC']} checked="checked" onclick="toggleRadio(event)">
<label for="delegate">send BLD/IBC toy tokens</label>
${clientText}

<input type="radio" id=${COMMANDS['CUSTOM_DENOMS_LIST']} name="command" value=${COMMANDS['CUSTOM_DENOMS_LIST']} onclick="toggleRadio(event)"}>
<label for=${COMMANDS['CUSTOM_DENOMS_LIST']}> Select Custom Denoms </label>

<br>


<br>
<div id='denoms' class="denomsClass">
Denoms: ${denomsDropDownHtml} <br> <br>
</div>
<input type="submit" />
</form>
<br>

<br>
<form action="/go" method="post">
<input type="hidden" name="command" value=${COMMANDS['FUND_PROV_POOL']} /><input type="submit" value="fund provision pool" />
</form>
</body></html>
`,
);
}
77 changes: 77 additions & 0 deletions bases/shared/instagoric-server/api/public-app/homeHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// @ts-check
import {
NETDOMAIN,
NETNAME,
namespace,
revision,
DOCKERIMAGE,
DOCKERTAG,
podname,
FAKE,
chainId,
} from '../../constants.js';
import { getDockerImage } from '../../utils.js';
import process from 'process';
export async function homeRoute(req, res) {
let CLUSTER_NAME;
let dockerImage = await getDockerImage(namespace, podname, FAKE);
const domain = NETDOMAIN;
const netname = NETNAME;
const gcloudLoggingDatasource = 'P470A85C5170C7A1D';
const logsQuery = {
'62l': {
datasource: gcloudLoggingDatasource,
queries: [
{
queryText: `resource.labels.container_name=\"log-slog\" resource.labels.namespace_name=\"${namespace}\" resource.labels.cluster_name=\"${CLUSTER_NAME}\"`,
},
],
},
};
const logsUrl = `https://monitor${domain}/explore?schemaVersion=1&panes=${encodeURI(
JSON.stringify(logsQuery),
)}&orgId=1`;
const dashboardUrl = `https://monitor${domain}/d/cdzujrg5sxvy8f/agoric-chain-metrics?var-cluster=${CLUSTER_NAME}&var-namespace=${namespace}&var-chain_id=${chainId}&orgId=1`;
res.send(`
<html><head><title>Instagoric</title></head><body><pre>
██╗███╗ ██╗███████╗████████╗ █████╗ ██████╗ ██████╗ ██████╗ ██╗ ██████╗
██║████╗ ██║██╔════╝╚══██╔══╝██╔══██╗██╔════╝ ██╔═══██╗██╔══██╗██║██╔════╝
██║██╔██╗ ██║███████╗ ██║ ███████║██║ ███╗██║ ██║██████╔╝██║██║
██║██║╚██╗██║╚════██║ ██║ ██╔══██║██║ ██║██║ ██║██╔══██╗██║██║
██║██║ ╚████║███████║ ██║ ██║ ██║╚██████╔╝╚██████╔╝██║ ██║██║╚██████╗
╚═╝╚═╝ ╚═══╝╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═════╝

Chain: ${chainId}${
process.env.NETPURPOSE !== undefined
? `\nPurpose: ${process.env.NETPURPOSE}`
: ''
}
Revision: ${revision}
Docker Image: ${DOCKERIMAGE || dockerImage.split(':')[0]}:${
DOCKERTAG || dockerImage.split(':')[1]
}
Revision Link: <a href="https://github.com/Agoric/agoric-sdk/tree/${revision}">https://github.com/Agoric/agoric-sdk/tree/${revision}</a>
Network Config: <a href="https://${netname}${domain}/network-config">https://${netname}${domain}/network-config</a>
Docker Compose: <a href="https://${netname}${domain}/docker-compose.yml">https://${netname}${domain}/docker-compose.yml</a>
RPC: <a href="https://${netname}.rpc${domain}">https://${netname}.rpc${domain}</a>
gRPC: <a href="https://${netname}.grpc${domain}">https://${netname}.grpc${domain}</a>
API: <a href="https://${netname}.api${domain}">https://${netname}.api${domain}</a>
Explorer: <a href="https://${netname}.explorer${domain}">https://${netname}.explorer${domain}</a>
Faucet: <a href="https://${netname}.faucet${domain}">https://${netname}.faucet${domain}</a>
Logs: <a href=${logsUrl}>Click Here</a>
Monitoring Dashboard: <a href=${dashboardUrl}>Click Here</a>
VStorage: <a href="https://vstorage.agoric.net/?path=&endpoint=https://${
netname === 'followmain' ? 'main-a' : netname
}.rpc.agoric.net">https://vstorage.agoric.net/?endpoint=https://${
netname === 'followmain' ? 'main-a' : netname
}.rpc.agoric.net</a>

UIs:
Main-branch Wallet: <a href="https://main.wallet-app.pages.dev/wallet/">https://main.wallet-app.pages.dev/wallet/</a>
Main-branch Vaults: <a href="https://dapp-inter-test.pages.dev/?network=${netname}">https://dapp-inter-test.pages.dev/?network=${netname}</a>

----
See more at <a href="https://agoric.com">https://agoric.com</a>
</pre></body></html>
`);
}
74 changes: 74 additions & 0 deletions bases/shared/instagoric-server/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// @ts-check
import { fs } from 'zx';
export const AG0_MODE = (process.env.AG0_MODE || 'false') === 'true';

export const COMMANDS = {
'SEND_BLD/IBC': 'send_bld_ibc',
SEND_AND_PROVISION_IST: 'send_ist_and_provision',
FUND_PROV_POOL: 'fund_provision_pool',
CUSTOM_DENOMS_LIST: 'custom_denoms_list',
};

export const BASE_AMOUNT = '25000000';

export const CLIENT_AMOUNT =
process.env.CLIENT_AMOUNT || '25000000uist,25000000ibc/toyusdc';
export const DELEGATE_AMOUNT =
process.env.DELEGATE_AMOUNT ||
'75000000ubld,25000000ibc/toyatom,25000000ibc/toyellie,25000000ibc/toyusdc,25000000ibc/toyollie';

export const PROVISIONING_POOL_ADDR =
'agoric1megzytg65cyrgzs6fvzxgrcqvwwl7ugpt62346';

export const TRANSACTION_STATUS = {
FAILED: 1000,
NOT_FOUND: 1001,
SUCCESSFUL: 1002,
};

export const DOCKERTAG = process.env.DOCKERTAG; // Optional.
export const DOCKERIMAGE = process.env.DOCKERIMAGE; // Optional.

export const NETNAME = process.env.NETNAME || 'devnet';
export const NETDOMAIN = process.env.NETDOMAIN || '.agoric.net';
export const agBinary = AG0_MODE ? 'ag0' : 'agd';

export const FAUCET_KEYNAME =
process.env.FAUCET_KEYNAME || process.env.WHALE_KEYNAME || 'self';

export const podname = process.env.POD_NAME || 'validator-primary';
export const INCLUDE_SEED = process.env.SEED_ENABLE || 'yes';
export const NODE_ID =
process.env.NODE_ID || 'fb86a0993c694c981a28fa1ebd1fd692f345348b';
export const RPC_PORT = 26657;
export const agoricHome = process.env.AGORIC_HOME;
export const chainId = process.env.CHAIN_ID;

export const namespace =
process.env.NAMESPACE ||
fs.readFileSync('/var/run/secrets/kubernetes.io/serviceaccount/namespace', {
encoding: 'utf8',
flag: 'r',
});

export const FAKE = process.env.FAKE || process.argv[2] === '--fake';

let revision;
if (FAKE) {
revision = 'fake_revision';
} else {
revision =
process.env.AG0_MODE === 'true'
? 'ag0'
: fs
.readFileSync(
'/usr/src/agoric-sdk/packages/solo/public/git-revision.txt',
{
encoding: 'utf8',
flag: 'r',
},
)
.trim();
}

export { revision };
Loading