@@ -7,9 +7,10 @@ import express from 'express';
77import https from 'https' ;
88import tmp from 'tmp' ;
99import { $ , fetch , fs , sleep } from 'zx' ;
10+ import multer from 'multer' ;
1011
1112import { makeSubscriptionKit } from '@agoric/notifier' ;
12-
13+ const upload = multer ( { dest : 'uploads/' } )
1314const { details : X } = globalThis . assert ;
1415
1516const CLIENT_AMOUNT =
@@ -20,14 +21,17 @@ const DELEGATE_AMOUNT =
2021const DOCKERTAG = process . env . DOCKERTAG ; // Optional.
2122const DOCKERIMAGE = process . env . DOCKERIMAGE ; // Optional.
2223const FAUCET_KEYNAME =
23- process . env . FAUCET_KEYNAME || process . env . WHALE_KEYNAME || 'self ' ;
24+ process . env . FAUCET_KEYNAME || process . env . WHALE_KEYNAME || 'bootstrap ' ;
2425const NETNAME = process . env . NETNAME || 'devnet' ;
2526const NETDOMAIN = process . env . NETDOMAIN || '.agoric.net' ;
2627const AG0_MODE = ( process . env . AG0_MODE || 'false' ) === 'true' ;
2728const agBinary = AG0_MODE ? 'ag0' : 'agd' ;
2829const podname = process . env . POD_NAME || 'validator-primary' ;
29- const INCLUDE_SEED = process . env . SEED_ENABLE || 'yes' ;
30- const NODE_ID = process . env . NODE_ID || 'fb86a0993c694c981a28fa1ebd1fd692f345348b' ;
30+ const INCLUDE_SEED = process . env . SEED_ENABLE || 'yes' ;
31+ const NODE_ID =
32+ process . env . NODE_ID || 'fb86a0993c694c981a28fa1ebd1fd692f345348b' ;
33+ const agoricHome =
34+ '~/Projects/agoric-sdk/packages/cosmic-swingset/t1/bootstrap' ;
3135
3236const FAKE = process . env . FAKE || process . argv [ 2 ] === '--fake' ;
3337if ( FAKE ) {
@@ -42,11 +46,10 @@ if (FAKE) {
4246 } ) ;
4347 // Create the temporary key.
4448 console . log ( `Creating temporary key` , { tmpDir, FAUCET_KEYNAME } ) ;
45- await $ `${ agBinary } --home=${ tmpDir } keys --keyring-backend=test add ${ FAUCET_KEYNAME } ` ;
49+ // await $`${agBinary} --home=${agoricHome } keys --keyring-backend=test add ${FAUCET_KEYNAME}`;
4650 process . env . AGORIC_HOME = tmpDir ;
4751}
4852
49- const agoricHome = process . env . AGORIC_HOME ;
5053assert ( agoricHome , X `AGORIC_HOME not set` ) ;
5154
5255const chainId = process . env . CHAIN_ID ;
@@ -62,7 +65,7 @@ const namespace =
6265 } ) ;
6366
6467const revision =
65- process . env . AG0_MODE === 'true'
68+ 1 || process . env . AG0_MODE === 'true'
6669 ? 'ag0'
6770 : fs
6871 . readFileSync (
@@ -150,11 +153,12 @@ const getNetworkConfig = async () => {
150153 `${ podname } .${ namespace } .svc.cluster.local` ,
151154 ) ;
152155 ap . peers [ 0 ] = ap . peers [ 0 ] . replace (
153- 'fb86a0993c694c981a28fa1ebd1fd692f345348b' , `${ NODE_ID } ` ,
156+ 'fb86a0993c694c981a28fa1ebd1fd692f345348b' ,
157+ `${ NODE_ID } ` ,
154158 ) ;
155159 ap . rpcAddrs = [ `https://${ NETNAME } .rpc${ NETDOMAIN } :443` ] ;
156160 ap . apiAddrs = [ `https://${ NETNAME } .api${ NETDOMAIN } :443` ] ;
157- if ( INCLUDE_SEED === 'yes' ) {
161+ if ( INCLUDE_SEED === 'yes' ) {
158162 ap . seeds [ 0 ] = ap . seeds [ 0 ] . replace (
159163 'seed.instagoric.svc.cluster.local' ,
160164 svc . get ( 'seed-ext' ) || `seed.${ namespace } .svc.cluster.local` ,
@@ -251,7 +255,9 @@ Chain: ${chainId}${
251255 : ''
252256 }
253257Revision: ${ revision }
254- Docker Image: ${ DOCKERIMAGE || dockerImage . split ( ':' ) [ 0 ] } :${ DOCKERTAG || dockerImage . split ( ':' ) [ 1 ] }
258+ Docker Image: ${ DOCKERIMAGE || dockerImage . split ( ':' ) [ 0 ] } :${
259+ DOCKERTAG || dockerImage . split ( ':' ) [ 1 ]
260+ }
255261Revision Link: <a href="https://github.com/Agoric/agoric-sdk/tree/${ revision } ">https://github.com/Agoric/agoric-sdk/tree/${ revision } </a>
256262Network Config: <a href="https://${ netname } ${ domain } /network-config">https://${ netname } ${ domain } /network-config</a>
257263Docker Compose: <a href="https://${ netname } ${ domain } /docker-compose.yml">https://${ netname } ${ domain } /docker-compose.yml</a>
@@ -287,6 +293,7 @@ publicapp.get('/metrics-config', async (req, res) => {
287293 res . send ( result ) ;
288294} ) ;
289295
296+
290297const dockerComposeYaml = ( dockerimage , dockertag , netname , netdomain ) => `\
291298version: "2.2"
292299services:
@@ -507,6 +514,80 @@ faucetapp.post('/go', (req, res) => {
507514 }
508515} ) ;
509516
517+ publicapp . get ( '/install-bundle' , async ( req , res ) => {
518+
519+ res . send ( `
520+ <!DOCTYPE html>
521+ <html lang="en">
522+ <head>
523+ <meta charset="UTF-8">
524+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
525+ <title>File Upload</title>
526+ </head>
527+ <body>
528+
529+ <h1>Upload a File</h1>
530+
531+ <form id="uploadForm" action="/install-bundle" method="POST" enctype="multipart/form-data">
532+ <input type="file" name="file" id="fileInput" required>
533+ <br><br>
534+ <button type="submit">Upload</button>
535+ </form>
536+
537+ <script>
538+ document.getElementById('uploadForm').addEventListener('submit', function(event) {
539+ event.preventDefault(); // Prevent the default form submission
540+
541+ const formData = new FormData();
542+ const fileInput = document.getElementById('fileInput');
543+
544+ if (fileInput.files.length === 0) {
545+ alert("Please select a file.");
546+ return;
547+ }
548+
549+ formData.append('file', fileInput.files[0]);
550+
551+ fetch('/install-bundle', {
552+ method: 'POST',
553+ body: formData
554+ })
555+ .then(response => response.json())
556+ .then(data => {
557+ alert('File uploaded successfully!');
558+ console.log(data);
559+ })
560+ .catch(error => {
561+ alert('Failed to upload file.');
562+ console.error('Error:', error);
563+ });
564+ });
565+ </script>
566+
567+ </body>
568+ </html>
569+
570+ ` ) ;
571+
572+ } ) ;
573+
574+ publicapp . post ( '/install-bundle' , upload . single ( 'file' ) , async ( req , res ) => {
575+ // Getting file from request and storing as temp file
576+ const bundle = ( req . file ?. filename ) ;
577+ console . log ( bundle ) ;
578+ const result = await $ `\
579+ ${ agBinary } tx swingset install-bundle --compress "@uploads/${ bundle } " \
580+ --from ${ FAUCET_KEYNAME } --keyring-backend=test --keyring-dir=${ agoricHome } --gas=auto \
581+ --chain-id=${ chainId } -b block --yes
582+ ` ;
583+ console . log ( '\n\n' , result ) ;
584+ if ( result . exitCode !== 0 ) {
585+ res . status ( 500 ) . send ( result . stderr ) ;
586+ return ;
587+ }
588+ res . status ( 200 ) . send ( 'success' ) ;
589+ } ) ;
590+
510591faucetapp . listen ( faucetport , ( ) => {
511592 console . log ( `faucetapp listening on port ${ faucetport } ` ) ;
512593} ) ;
0 commit comments