Asset management
@johansten in https://github.com/stellar/js-stellar-base/issues/66:
This would be an API breaking change, but can you please take a look at how you handle assets?
Seriously, assets are delivered as:
source_asset_type source_asset_code source_asset_issuer
destination_asset_type destination_asset_code destination_asset_issuer
asset_type asset_code asset_issuer
Right now I've got three version of the same bloody code,
if ($scope.send.asset.asset_type === 'native') {
asset = StellarSdk.Asset.native();
} else {
asset = new StellarSdk.Asset(
$scope.send.asset.asset_code,
$scope.send.asset.asset_issuer
);
}
just to get an Asset out of the json I get back from your API.
Obviously I could make that into one version by adding optional prefixes to the object property accessed, but why should I have go to that extent to get something that basic done?
How about breaking that up into a json-stanza, for easy conversion to an Asset object?
source_asset.whatever destination_asset.whatever asset.whatever
And then adding an Asset.from_json()
Ex. https://horizon-testnet.stellar.org/operations/7392858487132161 For backward compatibility we could add additional object field, like this:
{
"source_asset": {
"type": "credit_alphanum4",
"code": "USD",
"issuer": "GDFRAHLTQIJOPIOFRUOH2TXLNN6ZDBPHNBM2UDCHJKJ5IHAGFS66NSHQ"
},
"source_asset_type": "credit_alphanum4",
"source_asset_code": "USD",
"source_asset_issuer": "GDFRAHLTQIJOPIOFRUOH2TXLNN6ZDBPHNBM2UDCHJKJ5IHAGFS66NSHQ"
}