Broadcast transaction form

fixes #878
This commit is contained in:
softsimon
2021-10-19 15:37:45 +04:00
parent c257fbfdcb
commit 4046c3176f
10 changed files with 104 additions and 4 deletions

View File

@@ -69,7 +69,8 @@ class Server {
next();
})
.use(express.urlencoded({ extended: true }))
.use(express.json());
.use(express.text())
;
this.server = http.createServer(this.app);
this.wss = new WebSocket.Server({ server: this.server });

View File

@@ -768,8 +768,13 @@ class Routes {
public async $postTransaction(req: Request, res: Response) {
res.setHeader('content-type', 'text/plain');
try {
const rawtx = Object.keys(req.body)[0];
const txIdResult = await bitcoinApi.$sendRawTransaction(rawtx);
let rawTx;
if (typeof req.body === 'object') {
rawTx = Object.keys(req.body)[0];
} else {
rawTx = req.body;
}
const txIdResult = await bitcoinApi.$sendRawTransaction(rawTx);
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 })