Reputation: 65
EDIT:
I have created a package that is now released on GitHub under a GNU Public License. Thank you all very much for your help on this issue!
With this portion of script:
line = { TransactionType: "Payment",
Account: #{xagate},
Destination: #{destinationAddress},
Amount: {
currency: "TST",
value: "#{destAmount}",
issuer: "rKYHqy2QWbf5WThp7vdJAxTR3WBHKDh9xv"
}
I receive this error:
syntax error, unexpected tLABEL
Destination: #{destinationAddress},
^
What is causing this syntax error? The accepted answer below explains how to fix this error. As for the Ripple JSON, I discovered that the err29 for the rippled server software is a result of a missing Fee and Sequence field. If you are also experiencing this issue, the answer is being investigated in this thread: https://forum.ripple.com/viewtopic.php?f=2&t=15599
Upvotes: 3
Views: 22851
Reputation:
unexpected tLABEL
, in my experience, means that an expression or block has not ended correctly. Ruby is reading your code as
line = { TransactionType: "Payment",
Account: Destination: # STOPS HERE from error
line
is a hash that you are making. Hashes follow the formats: { key => value }
and { key: value }
. Looks like you are following the second format. As you see above, Ruby is reading your code as { key: {key: } }
where the value to the second key is missing.
Outside of a string, the #
symbol tells Ruby "everything from here to end-of-line is a comment." You can easily see this with the StackOverflow syntax highlighter marking Ruby comments as gray.
But inside a string, #
is used for string interpolation, which appears to be what you are trying to achieve. String interpolation includes double quotation marks wrapped around the text, like so: "Hello, #{planet}"
, where #{}
is where you place the variable.
This is how you would write your code, using string interpolation:
Account: "#{xagate}",
Destination: "#{destinationAddress}",
If you look later in your code, you are actually doing this with line[Amount][value]
(which is "#{destAmount}"
)
Since your string only contains the object interpolated, I would suggest the following instead. First, you can call to_s
on the object, converting it to a string. If the object was an array, the string would contain the commas and brackets. Second, you can simply do Account: xagate
. This is much simpler, as you can check the value against the variable, instead of a string containing the variable. (One less step to process!)
Finally, as you mentioned in chat, you are new to Ruby. It is standard convention that all objects starting with a capital letter (like Account
) refer to classes, and objects in caps are constants. This is not the reason for your error, although it is good practice to start fixing this now... To prevent issues possibly stemming from that.
Upvotes: 9
Reputation: 1364
change
Account: #{xagate},
Destination: #{destinationAddress},
to
Account: "#{xagate}",
Destination: "#{destinationAddress}",
Double quotes enclose strings which may contain expressions that should be interpolated. These expressions inside a string are marked with #{...}
Upvotes: 4