humblenginr / goocoin

Full bitcoin solution written in Go (golang)
Other
0 stars 0 forks source link

Unexpected behavior when entering an invalid Sequence #13

Closed piotrnar closed 1 week ago

piotrnar commented 1 week ago

This seems to be a problem that was created while merging the two functions into one make_tx(). Must be something wrong with how the error from make_tx() is being forwarded to the HTTP response.

Previously, when I an invalid Sequence was entered (e.g. -3000000), after clicking "Download payment.zip" a page would appear with an error message and a redirection after 5 seconds:

Screenshot 2024-09-04 210502

Now there is no message, only the redirection.

Obviously the same behavior is expected when clicking on the "Sign transaction button". But instead, now there is no error, only the alert("Sign transaction request sent to the remote wallet.") Then the gateway receives a sign request, but fails with the following message:

Creating necessary files...
open wallet/balance/: is a directory

The error forwarding needs to be fixed (in client/usif/webui/sendtx.go) and the alert "Sign transaction request sent to the remote wallet." ought to be moved to the "onreadystatechange" handler (when the returned status is 200).

piotrnar commented 1 week ago

A possible fix for this issue.

In client/usif/webui/sendtx.go - in both places where make_tx() is called from, it should be like this:

            er, thisbal, pay_cmd := make_tx(r.Form, tx)
            if er != "" {
                err = er
                goto error
            }

In client/www/templates/send.html function sign_transaction() should be like this:

function sign_transaction() {
    var data, xhr;
    data = new FormData(document.mainform);
    xhr = new XMLHttpRequest();

    xhr.open( 'POST', '/sign_transaction', true );
    xhr.onreadystatechange = function ( response ) {
         if (xhr.readyState == 4) {
             if(xhr.status != 200) {
                alert("Error: " + xhr.responseText)
             } else {
                 alert("Sign transaction request sent to the remote wallet.")
             }
         }
    };
    xhr.send( data );
    // Nithish: ideally we would want a loading sort of component, or a notification type of feature for this. But that is beyond the scope of this project
    // and can be implemented later
}
humblenginr commented 1 week ago

fixed in https://github.com/piotrnar/gocoin/pull/68/commits/b38dfaf7656c483ae03df9229344fe02cafdf016