payload: {"action":"created","issue":{"url":"https://api.github.com/repos/stellar/js-xdr/issues/25","repository_url":"https://api.github.com/repos/stellar/js-xdr","labels_url":"https://api.github.com/repos/stellar/js-xdr/issues/25/labels{/name}","comments_url":"https://api.github.com/repos/stellar/js-xdr/issues/25/comments","events_url":"https://api.github.com/repos/stellar/js-xdr/issues/25/events","html_url":"https://github.com/stellar/js-xdr/issues/25","id":409373408,"node_id":"MDU6SXNzdWU0MDkzNzM0MDg=","number":25,"title":"Allow XDR types to generate from / output to JSON","user":{"login":"morleyzhi","id":1668327,"node_id":"MDQ6VXNlcjE2NjgzMjc=","avatar_url":"https://avatars1.githubusercontent.com/u/1668327?v=4","gravatar_id":"","url":"https://api.github.com/users/morleyzhi","html_url":"https://github.com/morleyzhi","followers_url":"https://api.github.com/users/morleyzhi/followers","following_url":"https://api.github.com/users/morleyzhi/following{/other_user}","gists_url":"https://api.github.com/users/morleyzhi/gists{/gist_id}","starred_url":"https://api.github.com/users/morleyzhi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/morleyzhi/subscriptions","organizations_url":"https://api.github.com/users/morleyzhi/orgs","repos_url":"https://api.github.com/users/morleyzhi/repos","events_url":"https://api.github.com/users/morleyzhi/events{/privacy}","received_events_url":"https://api.github.com/users/morleyzhi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2019-02-12T16:00:59Z","updated_at":"2019-02-13T17:27:34Z","closed_at":null,"author_association":"MEMBER","body":"Broadly, this allows a developer to compose XDR representations in JSON and convert them into real XDR objects (and vice versa).\r\n\r\nThe developer story here is: a developer reads the XDR definition, writes the transaction / asset / whatever in JSON, then is able to convert it to an XDR.\r\n\r\nFor example, given the following XDR definition of `Transaction`:\r\n\r\n```xdr\r\nstruct Transaction\r\n{\r\n    // account used to run the transaction\r\n    AccountID sourceAccount;\r\n\r\n    // the fee the sourceAccount will pay\r\n    uint32 fee;\r\n\r\n    // sequence number to consume in the account\r\n    SequenceNumber seqNum;\r\n\r\n    // validity range (inclusive) for the last ledger close time\r\n    TimeBounds* timeBounds;\r\n\r\n    Memo memo;\r\n\r\n    Operation operations<100>;\r\n\r\n    // reserved for future use\r\n    union switch (int v)\r\n    {\r\n    case 0:\r\n        void;\r\n    }\r\n    ext;\r\n};\r\n```\r\nThe JSON would look like:\r\n```json\r\n{\r\n    \"sourceAccount\": \"G...\",\r\n    \"fee\": 100,\r\n    \"seqNum\": 1234,\r\n    \"timeBounds\": null,\r\n    \"memo\": {\r\n      \"type\": MEMO_NONE\r\n    },\r\n    \"operations\": [\r\n      {\r\n        \"sourceAccount\": null,\r\n        \"type\": CREATE_ACCOUNT,\r\n        \"destination\": \"G...\",\r\n        \"startingBalance\": 200000000\r\n      }\r\n    ]\r\n    \"ext\": 0 // maybe default to zero-value when omitted?\r\n};\r\n```\r\nThis example is for `Transaction` object but in general you should be able to do the same thing with any XDR object, you check it's definition, write JSON and you can quickly convert it to actual XDR representation. \r\n\r\nThere are some things to figure out:\r\n* How do you represent XDR union, ex:\r\n    ```xdr\r\n    union Memo switch (MemoType type)\r\n    {\r\n    case MEMO_NONE:\r\n        void;\r\n    case MEMO_TEXT:\r\n        string text<28>;\r\n    case MEMO_ID:\r\n        uint64 id;\r\n    case MEMO_HASH:\r\n        Hash hash; // the hash of what to pull from the content server\r\n    case MEMO_RETURN:\r\n        Hash retHash; // the hash of the tx you are rejecting\r\n    };\r\n    ```\r\n    An obvious way is to use union switch name `type`. So this would become:\r\n     ```js\r\n    memo = {\r\n      type: MEMO_TEXT,\r\n      text: \"Hello world!\"\r\n    }\r\n    ```\r\n    But maybe there's a better way? [SEP-0011](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0011.md) is responsible for very similar thing but is using a different format than JSON so you can check it out.\r\n* Some types are just bytes and we need to be able to pass a human-readable representation if there is any. For example, `AccountID` type (`sourceAccount` in `Transaction`) is `PublicKey` which is really:\r\n    ```xdr\r\n    union PublicKey switch (PublicKeyType type)\r\n    {\r\n    case PUBLIC_KEY_TYPE_ED25519:\r\n        uint256 ed25519;\r\n    };\r\n    ```\r\n    Would be great to have a helper methods to quickly create byte arrays, ex:\r\n    ```json\r\n    sourceAccount: AccountId(\"G...\"),\r\n    ```\r\n* Other types require some modifications from human-readable form (ex. all amounts). We should probably have helper functions for this as well.\r\n\r\n_Originally posted by @bartekn in https://github.com/stellar/js-stellar-base/pull/157#issuecomment-462704769_"},"comment":{"url":"https://api.github.com/repos/stellar/js-xdr/issues/comments/463289953","html_url":"https://github.com/stellar/js-xdr/issues/25#issuecomment-463289953","issue_url":"https://api.github.com/repos/stellar/js-xdr/issues/25","id":463289953,"node_id":"MDEyOklzc3VlQ29tbWVudDQ2MzI4OTk1Mw==","user":{"login":"bartekn","id":464938,"node_id":"MDQ6VXNlcjQ2NDkzOA==","avatar_url":"https://avatars1.githubusercontent.com/u/464938?v=4","gravatar_id":"","url":"https://api.github.com/users/bartekn","html_url":"https://github.com/bartekn","followers_url":"https://api.github.com/users/bartekn/followers","following_url":"https://api.github.com/users/bartekn/following{/other_user}","gists_url":"https://api.github.com/users/bartekn/gists{/gist_id}","starred_url":"https://api.github.com/users/bartekn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bartekn/subscriptions","organizations_url":"https://api.github.com/users/bartekn/orgs","repos_url":"https://api.github.com/users/bartekn/repos","events_url":"https://api.github.com/users/bartekn/events{/privacy}","received_events_url":"https://api.github.com/users/bartekn/received_events","type":"User","site_admin":false},"created_at":"2019-02-13T17:27:34Z","updated_at":"2019-02-13T17:27:34Z","author_association":"MEMBER","body":"> While JSON is clearly more human readable then XDR, it's still usually generated and consumed by computer programs.\r\n\r\nI don't agree with this statement. In JS, JSON is actually a native representation of objects and is used quite often.\r\n\r\nThe biggest problem we need to solve is that a lot of boilerplate code is needed to create more complicated XDR objects. Check [union example](https://github.com/stellar/js-xdr/blob/master/examples/union.js).\r\n\r\n> If it is meant for humans to interact with, maybe we can use **Tx**REP (SEP11) as is?\r\n\r\n> FWIW as I've said in other tickets, I'm leaning towards not introducing more than one way to solve a problem, so if it's just a matter of giving developers a different way of assembling **transactions**, I'd opt to not do it.\r\n\r\nIt's not about transactions only. If you want to do any other task related to XDR (ex. decode Ledger contents encoded in XDR) it's actually really hard to do using existing `js-xdr` APIs."}}
other: {"actor":{"display_login":"bartekn"}}