The ManageDataOp takes a dataName as String and dataValue as bytes but its failing and the data is not being stored, should I convert the value to base64 or is that done on the server? Should I pad it with zeroes to 64?

* Edit: To expand, here are the XDRs for {name: 'Play', value: 'Harder'}




So apparently it's not about the data fields.

* More info, here is the Transaction struct just in case something is out of place:

Transaction(sourceAccount: StellarSDK.PublicKey.ED25519(32 bytes), fee: 100, seqNum: 26195739977711772, timeBounds: Optional(StellarSDK.TimeBounds(minTime: 0, maxTime: 0)), memo: StellarSDK.Memo.None, operations: [StellarSDK.Operation(sourceAccount: Optional(StellarSDK.PublicKey.ED25519(32 bytes)), body: StellarSDK.OperationBody.ManageData(StellarSDK.ManageDataOp(dataName: "Play", dataValue: Optional(6 bytes))))], ext: 0)

  • Which SDK are you using? – Francesco Feb 11 '18 at 19:51
  • I am building my own in Swift – Kuyawa Feb 11 '18 at 19:59
  • Weird stuff, if the value has multiple of 4 bytes it's stored fine otherwise it fails. I'll check the XDR encoder just in case. – Kuyawa Feb 11 '18 at 20:35
  • 1
    Ah yes, I had the same issue working on mine. You have to encode the value as variable-length opaque data, the rfc shows the correct encoding for that. – Francesco Feb 12 '18 at 15:16

XDR values must always be a multiple of 4. See the "Basic Block Size" section here: https://docs.oracle.com/cd/E19683-01/816-1435/6m7rrfn9n/index.html

To provide some more details for this specific operation:

  1. "Name" is encoded as an XDR string. This means a 4-byte unsigned int indicating the length followed by the bytes representing the string. As always for XDR, this string must be padded with null bytes if its length is not a multiple of 4

  2. "Value" should be sent as the raw bytes and not base64 encoded. Horizon will base64 encode this value when sending it to API clients.

If you haven't seen it yet, the Stellar XDR specification will be very useful when writing your SDK: https://github.com/stellar/stellar-core/tree/master/src/xdr


Workaround: I ended up padding the bytes with zeroes in multiples of four and it worked. I don't know if that's a XDR requirement or a parser deficiency but it works for now.

Still open for more solutions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.