Jump to content
jargoman

why won't my ripple-lib code sign a trustline transaction

Recommended Posts

Posted (edited)
<script src="/Scripts/ripple-1.2.0.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.js" type="text/javascript"></script>


<script type="text/javascript">
    function SubmitTransaction() {
        const curr = document.getElementById("cur").innerHTML;
        document.getElementById("outcome").innerHTML += curr;

        const add = document.getElementById("ad").innerHTML;
        document.getElementById("outcome").innerHTML += add;

        const limit = document.getElementById("lim").innerHTML;
        document.getElementById("outcome").innerHTML += limit;

        const quin = document.getElementById("qin").innerHTML;
        document.getElementById("outcome").innerHTML += quin;

        const quout = document.getElementById("qout").innerHTML;
        document.getElementById("outcome").innerHTML += quout;

        const secr = document.getElementById("sec").value;

        document.getElementById("outcome").innerHTML += secr;




        const trustline =
        {
            currency: curr,
            counterparty: add,
            limit: limit,
        };

        //const trustline = JSON.stringify(JSON.parse(t));

        

        var api = new ripple.RippleAPI({ server: 'wss://s.altnet.rippletest.net:51233' });


        var isValid = api.isValidSecret(secr);



        document.getElementById("outcome").innerHTML += "<br>IsValid " + isValid;

        var keypair = api.deriveKeypair(secr)

        document.getElementById("outcome").innerHTML += "<br>Public Key " + keypair.publicKey;

        var address = api.deriveAddress(keypair.publicKey);

        document.getElementById("outcome").innerHTML += "<br>Address " + address;

        
        

        
        const instructions = { maxFee: 0.000250, maxLedgerVersionOffset: 50 };

        document.getElementById("outcome").innerHTML += "<br>Instructions " + JSON.stringify(instructions);


        api.connect().then(function () {


            document.getElementById("outcome").innerHTML += JSON.stringify(trustline);
            document.getElementById("outcome").innerHTML += "<br>Connected ";
            debugger;
            return api.prepareTrustline(address, trustline);
        }).then(function (prepared) {
            document.getElementById("outcome").innerHTML += "<br>prepared";

            document.getElementById("outcome").innerHTML += "<br>" + JSON.stringify(prepared);


                const signedTransaction = api.sign(prepared.txJSON, secr);

                document.getElementById("outcome").innerHTML += "<br>signed = " + JSON.stringify(signedTransaction);

                api.submit(signedTransaction);
        });

    }
  </script>

 

the code halts when calling prepareTrustline and reports the following errors. 
 

instance.trustline.currency does not match pattern "^([a-zA-Z0-9<>(){}[\\]|?!@#$%^&*]{3}|[A-F0-9]{40}|drops)$",

instance.trustline.counterparty does not conform to the "address" 

format,instance.trustline.counterparty does not match pattern "^r[1-9A-HJ-NP-Za-km-z]{25,34}$",

instance.trustline.limit does not match pattern "^[0-9]*[.]?[0-9]+([eE][-+]?[0-9]+)?$"

but the debugger reports trustline.currency as type string 

curr = "TST";
counterparty={valid ripple address string};
limit I've tried both int and string .

is this a scope issue? I'm new to javascript but not programming 

trustlineproblem.PNG

Edited by jargoman
removed duplicate lines of code

Share this post


Link to post
Share on other sites
1 hour ago, tulo said:

You have the endlines "\n" in the strings. Also an initial space.

Thank you I thought it didn't matter. json's white space is supposed to be irrelevant.

Share this post


Link to post
Share on other sites
25 minutes ago, jargoman said:

Thank you I thought it didn't matter. json's white space is supposed to be irrelevant.

In the string it's a character as in any other language ;).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...