Merge pull request #881 from mempool/simon/tx-push-endpoint
Post TX API for HTML forms
This commit is contained in:
		
						commit
						9bef7da210
					
				@ -170,6 +170,7 @@ class Server {
 | 
				
			|||||||
      .get(config.MEMPOOL.API_URL_PREFIX + 'backend-info', routes.getBackendInfo)
 | 
					      .get(config.MEMPOOL.API_URL_PREFIX + 'backend-info', routes.getBackendInfo)
 | 
				
			||||||
      .get(config.MEMPOOL.API_URL_PREFIX + 'init-data', routes.getInitData)
 | 
					      .get(config.MEMPOOL.API_URL_PREFIX + 'init-data', routes.getInitData)
 | 
				
			||||||
      .get(config.MEMPOOL.API_URL_PREFIX + 'validate-address/:address', routes.validateAddress)
 | 
					      .get(config.MEMPOOL.API_URL_PREFIX + 'validate-address/:address', routes.validateAddress)
 | 
				
			||||||
 | 
					      .post(config.MEMPOOL.API_URL_PREFIX + 'tx/push', routes.$postTransactionForm)
 | 
				
			||||||
      .get(config.MEMPOOL.API_URL_PREFIX + 'donations', async (req, res) => {
 | 
					      .get(config.MEMPOOL.API_URL_PREFIX + 'donations', async (req, res) => {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
          const response = await axios.get('https://mempool.space/api/v1/donations', { responseType: 'stream', timeout: 10000 });
 | 
					          const response = await axios.get('https://mempool.space/api/v1/donations', { responseType: 'stream', timeout: 10000 });
 | 
				
			||||||
 | 
				
			|||||||
@ -791,6 +791,22 @@ class Routes {
 | 
				
			|||||||
        : (e.message || 'Error'));
 | 
					        : (e.message || 'Error'));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public async $postTransactionForm(req: Request, res: Response) {
 | 
				
			||||||
 | 
					    res.setHeader('content-type', 'text/plain');
 | 
				
			||||||
 | 
					    const matches = /tx=([a-z0-9]+)/.exec(req.body);
 | 
				
			||||||
 | 
					    let txHex = '';
 | 
				
			||||||
 | 
					    if (matches && matches[1]) {
 | 
				
			||||||
 | 
					      txHex = matches[1];
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					      const txIdResult = await bitcoinClient.sendRawTransaction(txHex);
 | 
				
			||||||
 | 
					      res.send(txIdResult);
 | 
				
			||||||
 | 
					    } catch (e: any) {
 | 
				
			||||||
 | 
					      res.status(400).send(e.message && e.code ? 'sendrawtransaction RPC error: ' + JSON.stringify({ code: e.code, message: e.message })
 | 
				
			||||||
 | 
					        : (e.message || 'Error'));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default new Routes();
 | 
					export default new Routes();
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user