@@ -51,6 +51,15 @@ app.get("/api/v1/version", (req: Request, res: Response) => {
5151 res . send ( version ) ;
5252} ) ;
5353
54+ // POST /api/v1/rocketpool-command-custom
55+ app . post ( "/api/v1/rocketpool-command-custom" , ( req : Request , res : Response ) => {
56+ console . log ( req . body . cmd ) ;
57+ var result = shelljs . exec (
58+ `/usr/local/bin/rocketpoold --settings /app/rocketpool/user-settings.yml api ${ req . body . cmd } `
59+ ) . stdout ;
60+ res . send ( result ) ;
61+ } ) ;
62+
5463// POST /api/v1/rocketpool-command
5564app . post ( "/api/v1/rocketpool-command" , ( req : Request , res : Response ) => {
5665 console . log ( req . body . cmd ) ;
@@ -74,16 +83,22 @@ function executeCommand(cmd: string) {
7483 return result ;
7584}
7685
86+ // POST /api/v1/minipool/import
87+ app . post ( "/api/v1/minipool/import" , async ( req : Request , res : Response ) => {
88+ console . log ( "Try to import key to the brain" ) ;
89+ res . send ( await importKey ( req . body . pubkey ) ) ;
90+ } ) ;
91+
7792// function that imports the keys from teku to a given url
78- function importKey ( validatorPubkey : string ) {
93+ async function importKey ( validatorPubkey : string ) : Promise < ImportKeyResponseData > {
7994 console . log ( "Import key to the brain" ) ;
8095 var keystoreJson = shelljs . exec (
8196 `cat /rocketpool/data/validators/teku/keys/${ validatorPubkey } .json`
8297 ) . stdout ;
8398 var password = shelljs . exec (
8499 `cat /rocketpool/data/validators/teku/passwords/${ validatorPubkey } .txt`
85100 ) . stdout ;
86- postValidatorData ( {
101+ return await postValidatorData ( {
87102 keystores : [ keystoreJson ] ,
88103 passwords : [ password ] ,
89104 tags : [ "rocketpool" ] ,
@@ -92,7 +107,7 @@ function importKey(validatorPubkey: string) {
92107}
93108
94109// async function to POST fetch
95- async function postValidatorData ( data = { } ) {
110+ async function postValidatorData ( data = { } ) : Promise < ImportKeyResponseData > {
96111 const response = await fetch (
97112 `${ appConfig . getConfig ( ) . brainAPIUrl } /eth/v1/keystores` ,
98113 {
@@ -103,9 +118,16 @@ async function postValidatorData(data = {}) {
103118 ) ;
104119 console . log ( response . ok ) ;
105120 if ( response . ok ) {
106- const { data } : { data : IImportKeyResponseData } = await response . json ( ) ;
121+ const { data } : { data : ImportKeyResponseData } = await response . json ( ) ;
107122 console . log ( data ) ;
123+ return data ;
108124 }
125+ return {
126+ data : [ {
127+ status : "error" ,
128+ message : "Keystore cannot be imported" ,
129+ } ]
130+ } ;
109131}
110132
111133app . listen ( API_PORT , ( ) => {
@@ -116,10 +138,10 @@ String.prototype.startsWith = function (str) {
116138 return this . indexOf ( str ) === 0 ;
117139} ;
118140
119- interface IImportKeyResponseData {
120- data : IImportKeyResponse [ ] ;
141+ interface ImportKeyResponseData {
142+ data : ImportKeyResponse [ ] ;
121143}
122- interface IImportKeyResponse {
144+ interface ImportKeyResponse {
123145 status : string ;
124146 message ?: string ;
125147}
0 commit comments