Greetings XLM Community! I hope your weekend is going well and you are all staying safe and happy.
As DevNullProd prepares it's submission for the SCF Seed Fund, we've been looking into some of the technical aspects of the XLM protocol as we flush out our MVP. A particular sticking point that we've encountered is around the External Data Representation (XDR) format that XLM uses to represent data such as transaction envelopes and results.
We haven't been able to find extensive documentation pertaining to this format, and will need to dive into it in our application. Take the following javascript code for example:
`var StellarSdk = require('stellar-sdk')
var server = new StellarSdk.Server('https://horizon.stellar.org');
var es = server.transactions()
.transaction("73ccc1c241fe314baa0280c7629b98644469faccdfdb0add654ae7e9b0dc9818")
.call()
.then(function(tx){
console.log("Envelope:")
console.log(JSON.stringify(StellarSdk.xdr.TransactionEnvelope.fromXDR(tx.envelope_xdr, 'base64'), null, " "));
})`
This results in the following:
Envelope:
{
"_switch": {
"name": "envelopeTypeTx",
"value": 2
},
"_arm": "v1",
"_value": {
"_attributes": {
"tx": {
"_attributes": {
"sourceAccount": {
"_switch": {
"name": "keyTypeEd25519",
"value": 0
},
"_arm": "ed25519",
"_armType": {
"_length": 32,
"_padding": 0
},
"_value": {
"type": "Buffer",
"data": [
153,
199,
<snip>
]
}
},
"fee": 2000,
"seqNum": {
"low": 3340403,
"high": 27330061,
"unsigned": false
},
"timeBounds": {
"_attributes": {
"minTime": {
"low": 0,
"high": 0,
"unsigned": true
},
"maxTime": {
"low": 1606681728,
"high": 0,
"unsigned": true
}
}
},
"memo": {
"_switch": {
"name": "memoNone",
"value": 0
},
"_arm": {},
"_armType": {}
},
"operations": [
{
"_attributes": {
"body": {
"_switch": {
"name": "manageBuyOffer",
"value": 12
},
"_arm": "manageBuyOfferOp",
"_value": {
"_attributes": {
"selling": {
"_switch": {
"name": "assetTypeCreditAlphanum4",
"value": 1
},
"_arm": "alphaNum4",
"_value": {
"_attributes": {
"assetCode": {
"type": "Buffer",
"data": [
85,
83,
68,
0
]
},
"issuer": {
"_switch": {
"name": "publicKeyTypeEd25519",
"value": 0
},
"_arm": "ed25519",
"_armType": {
"_length": 32,
"_padding": 0
},
"_value": {
"type": "Buffer",
"data": [
232,
166,
<snip>
]
}
}
}
}
},
"buying": {
"_switch": {
"name": "assetTypeNative",
"value": 0
},
"_arm": {},
"_armType": {}
},
"buyAmount": {
"low": 0,
"high": 0,
"unsigned": false
},
"price": {
"_attributes": {
"n": 1,
"d": 10000
}
},
"offerId": {
"low": 378761140,
"high": 0,
"unsigned": false
}
}
}
}
}
},
{
"_attributes": {
"body": {
"_switch": {
"name": "manageBuyOffer",
"value": 12
},
"_arm": "manageBuyOfferOp",
"_value": {
"_attributes": {
"selling": {
"_switch": {
"name": "assetTypeCreditAlphanum4",
"value": 1
},
"_arm": "alphaNum4",
"_value": {
"_attributes": {
"assetCode": {
"type": "Buffer",
"data": [
85,
83,
68,
0
]
},
"issuer": {
"_switch": {
"name": "publicKeyTypeEd25519",
"value": 0
},
"_arm": "ed25519",
"_armType": {
"_length": 32,
"_padding": 0
},
"_value": {
"type": "Buffer",
"data": [
232,
166,
<snip>
]
}
}
}
}
},
"buying": {
"_switch": {
"name": "assetTypeNative",
"value": 0
},
"_arm": {},
"_armType": {}
},
"buyAmount": {
"low": 674980527,
"high": 3,
"unsigned": false
},
"price": {
"_attributes": {
"n": 300455075,
"d": 1568229641
}
},
"offerId": {
"low": 0,
"high": 0,
"unsigned": false
}
}
}
}
}
}
],
"ext": {
"_switch": 0,
"_arm": {},
"_armType": {}
}
}
},
"signatures": [
{
"_attributes": {
"hint": {
"type": "Buffer",
"data": [
27,
205,
218,
206
]
},
"signature": {
"type": "Buffer",
"data": [
106,
76,
<snip>
]
}
}
}
]
}
}
}
Our question is how to interpret these various fields. We can take a guess at some things, things like _switch indicate an enumeration of one of several values, but the semantics of other things such as _arm, _armtype, etc are unclear, as well as how to best unserialize buffers into human friendly strings.
The XDR definition files help somewhat in terms of the structure of serialized objects but what would be of most use would be developer documentation on how to interpret this data and use it in an external application. Additional some code examples on how to parse and use the data would be of great assistance.
Any insights into this would be highly appreciated!