Bitcoin Forum
May 22, 2024, 12:18:09 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Empty error message in "broadcast" API function (but not in console) [SOLVED]  (Read 72 times)
NotATether (OP)
Legendary
*
Offline Offline

Activity: 1610
Merit: 6753


bitcoincleanup.com / bitmixlist.org


View Profile WWW
November 25, 2021, 04:01:13 PM
Last edit: November 25, 2021, 04:32:22 PM by NotATether
Merited by OmegaStarScream (4), hugeblack (4), pooya87 (3), RickDeckard (1), PawGo (1)
 #1

I am making HTTPS wrappers around a few Electrum commands, one of them being "broadcast". I already have methods for both "payto" and "signtransaction" that work correctly. But when I try to call "broadcast" from the API, I get an error back from Electrum but with an empty message string and code "1":

Code:
{"id":"curltext","jsonrpc":"2.0","error":{"code":1,"message":""}}

I'm making a POST request with application/x-www-form-urlencoded type with the following body:

Code:
{"jsonrpc":"2.0","id":"curltext","method":"broadcast","params":{"tx": tx}} // where tx is supplied from "signtransaction"

Strangely, this method works fine when I call it from the command line.

Without the error message, I'm at a loss at what could possibly be the problem.

It is definitely not an error in my HTTPS setup because another network function (getinfo) returns successfully and shows I'm connected to an electrum server.

So it is clearly a problem with the "broadcast" command (in particular, some exception was raised somewhere inside it, without the error message, so that narrows the problem down a little. The Timeout exception is one such possibility but this is practically impossible to occur on a 1Gbps line).

Electrum version: 4.1.5



EDIT: Apparently, I found that the reason the method was failing so mysteriously was because there were literal double quotes in the tx at the beginning and end. I had plainly reused the output of "signtransaction", which is strange because the "signtransaction" RPC handles the result of the "payto" RPC - which also has double quotes around it - just fine.

It probably means (and I'm just speculating) Electrum literally pushes your transaction to a server which then forwards it to a bitcoin node with the literal double quotes still inside.

So, for anyone else who happens across this thread in the future, always remove the quotes from your tx string (using array slices) before broadcasting it with Electrum.  Smiley

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
pooya87
Legendary
*
Offline Offline

Activity: 3458
Merit: 10576



View Profile
November 27, 2021, 04:12:58 AM
Merited by hugeblack (1)
 #2

Are you by any chance manually creating a string with "curly braces", "commas", etc. in it?

If yes, this was your mistake. When you want to create a JSON object it is always best to create a JSON object not a string by hand. There should be libraries for it in all languages. For example you define tx then set its value to a hexadecimal string. In the end you use the ToString or ConvertToString method on that object to convert it to a string and use that result to send to the server.

It probably means (and I'm just speculating) Electrum literally pushes your transaction to a server which then forwards it to a bitcoin node with the literal double quotes still inside.
Electrum "servers" are themselves full nodes, they receive your messages, parse the JSON and act accordingly.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
NotATether (OP)
Legendary
*
Offline Offline

Activity: 1610
Merit: 6753


bitcoincleanup.com / bitmixlist.org


View Profile WWW
November 27, 2021, 06:06:25 AM
 #3

Are you by any chance manually creating a string with "curly braces", "commas", etc. in it?

No strings are created by hand except for the address and amount argument supplied to "payto" command, which had always worked fine.

I directly supplied the return value of that to the "tx" argument of "signtransaction" (which also worked for some reason), who's return value I passed to "tx" argument to "broadcast" (this was where the error would occur)

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!