astroband / ruby-stellar-sdk

Community maintained Ruby SDK for Stellar
72 stars 44 forks source link

`Stellar::Memo.new` should validate memo length #90

Open jimdanz opened 6 years ago

jimdanz commented 6 years ago

Stellar::Memo.new seems to validate that the memo provided is the right data type:

[36] pry(main)> Stellar::Memo.new(:memo_text, {foo: 'bar'})
XDR::InvalidValueError: XDR::InvalidValueError
from .../gems/xdr-3.0.0/lib/xdr/union.rb:86:in `set'

But it does not look at the value itself to validate length:

[37] pry(main)> Stellar::Memo.new(:memo_text, 'x' * 10000)
=> #<Stellar::Memo:0x007fdc5f3a7198
 @arm=:text,
 @switch=#<Stellar::MemoType:0x007fdc5d80e800 @name="memo_text", @value=1>,
 .....

From my perspective it'd be great if the contract were that if Stellar::Memo.new returns a value, that value will be able to be serialized into XDR successfully.

ramontayag commented 5 years ago

@jimdanz thanks for mentioning this. We'd love a PR!