How to decode stellar XDR












0















I am working on stellar blockchain and need to decode stellar XDR which is in GO language. I know how to decode using JavaScript but couldn't find a way to do it in GO.



 //JS code

const {Transaction} = require('stellar-base')

const parsedTx = new Transaction('tx_envelope_encoded_as_XDR')
console.log(parsedTx)


This works fine. what i have tried and not working...



//GO code

import (

"bytes"
"encoding/json"
"fmt"
"net/http"
"github.com/stellar/go/xdr"
"github.com/gorilla/mux"

)

func DecodeXDR(w http.ResponseWriter, r *http.Request) {

var OBJ model.TransactionCollectionBody
err := json.NewDecoder(r.Body).Decode(&OBJ)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
json.NewEncoder(w).Encode("Error while Decoding the body")
fmt.Println(err)

return
}

// fmt.Println(OBJ)

// lol:=xdr.Value(OBJ.XDR)

var txe xdr.Transaction
err = xdr.SafeUnmarshalBase64(XDRB64, &txe)
if err != nil {
fmt.Println(err)
}

fmt.Println(txe)

}

//Output
{{PublicKeyTypePublicKeyTypeEd25519 0xc042055d20} 200 2800572080062465 <nil> {MemoTypeMemoNone <nil> <nil> <nil> <nil>} [{<nil> {OperationTypeManageData <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> 0xc042174040 <nil>}} {<nil> {OperationTypeManageData <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> 0xc042174080 <nil>}}] {0}}


//Expected Output



{ type: 'payment',
destination: 'GCKUXI3JRJANYOF3AM35Z22FGUGYYUIEBPE5TTZ7P3G6XAEFGYZC2POM',
asset:
Asset {
code: 'Blog',
issuer: 'GDOPTRADBVWJR6BMB6H5ACQTAVUS6XMT53CDNAJZLOSTIUICIW57ISMF' },
amount: '10' }



{ type: 'payment',
destination: 'GCKUXI3JRJANYOF3AM35Z22FGUGYYUIEBPE5TTZ7P3G6XAEFGYZC2POM',
asset:
Asset {
code: 'Blog',
issuer: 'GDOPTRADBVWJR6BMB6H5ACQTAVUS6XMT53CDNAJZLOSTIUICIW57ISMF' },
amount: '10' }



{ type: 'payment',
destination: 'GCKUXI3JRJANYOF3AM35Z22FGUGYYUIEBPE5TTZ7P3G6XAEFGYZC2POM',
asset:
Asset {
code: 'Blog',
issuer: 'GDOPTRADBVWJR6BMB6H5ACQTAVUS6XMT53CDNAJZLOSTIUICIW57ISMF' },
amount: '10' }



Can anyone help me to solve this?










share|improve this question




















  • 1





    "not working" isn't a helpful problem description. Be specific.

    – Peter
    Nov 13 '18 at 8:28











  • I am using SafeUnmarshalBase64 to unmarshal the XDR which is in base 64 format and it gives an byte stream output shown above as //Output. But what i actually want is something (set of operations performed under that public key) which is readable like //Expected Output.

    – Thanan_Jaje
    Nov 15 '18 at 5:04











  • It seems that you can decode the transaction just fine, but your expectation makes no sense. xdr.Transaction has none of the fields shown in the expected output. Also Println produces the standard format for structs and that's not something resembling JavaScript.

    – Peter
    Nov 15 '18 at 9:37
















0















I am working on stellar blockchain and need to decode stellar XDR which is in GO language. I know how to decode using JavaScript but couldn't find a way to do it in GO.



 //JS code

const {Transaction} = require('stellar-base')

const parsedTx = new Transaction('tx_envelope_encoded_as_XDR')
console.log(parsedTx)


This works fine. what i have tried and not working...



//GO code

import (

"bytes"
"encoding/json"
"fmt"
"net/http"
"github.com/stellar/go/xdr"
"github.com/gorilla/mux"

)

func DecodeXDR(w http.ResponseWriter, r *http.Request) {

var OBJ model.TransactionCollectionBody
err := json.NewDecoder(r.Body).Decode(&OBJ)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
json.NewEncoder(w).Encode("Error while Decoding the body")
fmt.Println(err)

return
}

// fmt.Println(OBJ)

// lol:=xdr.Value(OBJ.XDR)

var txe xdr.Transaction
err = xdr.SafeUnmarshalBase64(XDRB64, &txe)
if err != nil {
fmt.Println(err)
}

fmt.Println(txe)

}

//Output
{{PublicKeyTypePublicKeyTypeEd25519 0xc042055d20} 200 2800572080062465 <nil> {MemoTypeMemoNone <nil> <nil> <nil> <nil>} [{<nil> {OperationTypeManageData <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> 0xc042174040 <nil>}} {<nil> {OperationTypeManageData <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> 0xc042174080 <nil>}}] {0}}


//Expected Output



{ type: 'payment',
destination: 'GCKUXI3JRJANYOF3AM35Z22FGUGYYUIEBPE5TTZ7P3G6XAEFGYZC2POM',
asset:
Asset {
code: 'Blog',
issuer: 'GDOPTRADBVWJR6BMB6H5ACQTAVUS6XMT53CDNAJZLOSTIUICIW57ISMF' },
amount: '10' }



{ type: 'payment',
destination: 'GCKUXI3JRJANYOF3AM35Z22FGUGYYUIEBPE5TTZ7P3G6XAEFGYZC2POM',
asset:
Asset {
code: 'Blog',
issuer: 'GDOPTRADBVWJR6BMB6H5ACQTAVUS6XMT53CDNAJZLOSTIUICIW57ISMF' },
amount: '10' }



{ type: 'payment',
destination: 'GCKUXI3JRJANYOF3AM35Z22FGUGYYUIEBPE5TTZ7P3G6XAEFGYZC2POM',
asset:
Asset {
code: 'Blog',
issuer: 'GDOPTRADBVWJR6BMB6H5ACQTAVUS6XMT53CDNAJZLOSTIUICIW57ISMF' },
amount: '10' }



Can anyone help me to solve this?










share|improve this question




















  • 1





    "not working" isn't a helpful problem description. Be specific.

    – Peter
    Nov 13 '18 at 8:28











  • I am using SafeUnmarshalBase64 to unmarshal the XDR which is in base 64 format and it gives an byte stream output shown above as //Output. But what i actually want is something (set of operations performed under that public key) which is readable like //Expected Output.

    – Thanan_Jaje
    Nov 15 '18 at 5:04











  • It seems that you can decode the transaction just fine, but your expectation makes no sense. xdr.Transaction has none of the fields shown in the expected output. Also Println produces the standard format for structs and that's not something resembling JavaScript.

    – Peter
    Nov 15 '18 at 9:37














0












0








0


0






I am working on stellar blockchain and need to decode stellar XDR which is in GO language. I know how to decode using JavaScript but couldn't find a way to do it in GO.



 //JS code

const {Transaction} = require('stellar-base')

const parsedTx = new Transaction('tx_envelope_encoded_as_XDR')
console.log(parsedTx)


This works fine. what i have tried and not working...



//GO code

import (

"bytes"
"encoding/json"
"fmt"
"net/http"
"github.com/stellar/go/xdr"
"github.com/gorilla/mux"

)

func DecodeXDR(w http.ResponseWriter, r *http.Request) {

var OBJ model.TransactionCollectionBody
err := json.NewDecoder(r.Body).Decode(&OBJ)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
json.NewEncoder(w).Encode("Error while Decoding the body")
fmt.Println(err)

return
}

// fmt.Println(OBJ)

// lol:=xdr.Value(OBJ.XDR)

var txe xdr.Transaction
err = xdr.SafeUnmarshalBase64(XDRB64, &txe)
if err != nil {
fmt.Println(err)
}

fmt.Println(txe)

}

//Output
{{PublicKeyTypePublicKeyTypeEd25519 0xc042055d20} 200 2800572080062465 <nil> {MemoTypeMemoNone <nil> <nil> <nil> <nil>} [{<nil> {OperationTypeManageData <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> 0xc042174040 <nil>}} {<nil> {OperationTypeManageData <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> 0xc042174080 <nil>}}] {0}}


//Expected Output



{ type: 'payment',
destination: 'GCKUXI3JRJANYOF3AM35Z22FGUGYYUIEBPE5TTZ7P3G6XAEFGYZC2POM',
asset:
Asset {
code: 'Blog',
issuer: 'GDOPTRADBVWJR6BMB6H5ACQTAVUS6XMT53CDNAJZLOSTIUICIW57ISMF' },
amount: '10' }



{ type: 'payment',
destination: 'GCKUXI3JRJANYOF3AM35Z22FGUGYYUIEBPE5TTZ7P3G6XAEFGYZC2POM',
asset:
Asset {
code: 'Blog',
issuer: 'GDOPTRADBVWJR6BMB6H5ACQTAVUS6XMT53CDNAJZLOSTIUICIW57ISMF' },
amount: '10' }



{ type: 'payment',
destination: 'GCKUXI3JRJANYOF3AM35Z22FGUGYYUIEBPE5TTZ7P3G6XAEFGYZC2POM',
asset:
Asset {
code: 'Blog',
issuer: 'GDOPTRADBVWJR6BMB6H5ACQTAVUS6XMT53CDNAJZLOSTIUICIW57ISMF' },
amount: '10' }



Can anyone help me to solve this?










share|improve this question
















I am working on stellar blockchain and need to decode stellar XDR which is in GO language. I know how to decode using JavaScript but couldn't find a way to do it in GO.



 //JS code

const {Transaction} = require('stellar-base')

const parsedTx = new Transaction('tx_envelope_encoded_as_XDR')
console.log(parsedTx)


This works fine. what i have tried and not working...



//GO code

import (

"bytes"
"encoding/json"
"fmt"
"net/http"
"github.com/stellar/go/xdr"
"github.com/gorilla/mux"

)

func DecodeXDR(w http.ResponseWriter, r *http.Request) {

var OBJ model.TransactionCollectionBody
err := json.NewDecoder(r.Body).Decode(&OBJ)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
json.NewEncoder(w).Encode("Error while Decoding the body")
fmt.Println(err)

return
}

// fmt.Println(OBJ)

// lol:=xdr.Value(OBJ.XDR)

var txe xdr.Transaction
err = xdr.SafeUnmarshalBase64(XDRB64, &txe)
if err != nil {
fmt.Println(err)
}

fmt.Println(txe)

}

//Output
{{PublicKeyTypePublicKeyTypeEd25519 0xc042055d20} 200 2800572080062465 <nil> {MemoTypeMemoNone <nil> <nil> <nil> <nil>} [{<nil> {OperationTypeManageData <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> 0xc042174040 <nil>}} {<nil> {OperationTypeManageData <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> <nil> 0xc042174080 <nil>}}] {0}}


//Expected Output



{ type: 'payment',
destination: 'GCKUXI3JRJANYOF3AM35Z22FGUGYYUIEBPE5TTZ7P3G6XAEFGYZC2POM',
asset:
Asset {
code: 'Blog',
issuer: 'GDOPTRADBVWJR6BMB6H5ACQTAVUS6XMT53CDNAJZLOSTIUICIW57ISMF' },
amount: '10' }



{ type: 'payment',
destination: 'GCKUXI3JRJANYOF3AM35Z22FGUGYYUIEBPE5TTZ7P3G6XAEFGYZC2POM',
asset:
Asset {
code: 'Blog',
issuer: 'GDOPTRADBVWJR6BMB6H5ACQTAVUS6XMT53CDNAJZLOSTIUICIW57ISMF' },
amount: '10' }



{ type: 'payment',
destination: 'GCKUXI3JRJANYOF3AM35Z22FGUGYYUIEBPE5TTZ7P3G6XAEFGYZC2POM',
asset:
Asset {
code: 'Blog',
issuer: 'GDOPTRADBVWJR6BMB6H5ACQTAVUS6XMT53CDNAJZLOSTIUICIW57ISMF' },
amount: '10' }



Can anyone help me to solve this?







go blockchain xdr stellar






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 5:12







Thanan_Jaje

















asked Nov 13 '18 at 6:47









Thanan_JajeThanan_Jaje

13




13








  • 1





    "not working" isn't a helpful problem description. Be specific.

    – Peter
    Nov 13 '18 at 8:28











  • I am using SafeUnmarshalBase64 to unmarshal the XDR which is in base 64 format and it gives an byte stream output shown above as //Output. But what i actually want is something (set of operations performed under that public key) which is readable like //Expected Output.

    – Thanan_Jaje
    Nov 15 '18 at 5:04











  • It seems that you can decode the transaction just fine, but your expectation makes no sense. xdr.Transaction has none of the fields shown in the expected output. Also Println produces the standard format for structs and that's not something resembling JavaScript.

    – Peter
    Nov 15 '18 at 9:37














  • 1





    "not working" isn't a helpful problem description. Be specific.

    – Peter
    Nov 13 '18 at 8:28











  • I am using SafeUnmarshalBase64 to unmarshal the XDR which is in base 64 format and it gives an byte stream output shown above as //Output. But what i actually want is something (set of operations performed under that public key) which is readable like //Expected Output.

    – Thanan_Jaje
    Nov 15 '18 at 5:04











  • It seems that you can decode the transaction just fine, but your expectation makes no sense. xdr.Transaction has none of the fields shown in the expected output. Also Println produces the standard format for structs and that's not something resembling JavaScript.

    – Peter
    Nov 15 '18 at 9:37








1




1





"not working" isn't a helpful problem description. Be specific.

– Peter
Nov 13 '18 at 8:28





"not working" isn't a helpful problem description. Be specific.

– Peter
Nov 13 '18 at 8:28













I am using SafeUnmarshalBase64 to unmarshal the XDR which is in base 64 format and it gives an byte stream output shown above as //Output. But what i actually want is something (set of operations performed under that public key) which is readable like //Expected Output.

– Thanan_Jaje
Nov 15 '18 at 5:04





I am using SafeUnmarshalBase64 to unmarshal the XDR which is in base 64 format and it gives an byte stream output shown above as //Output. But what i actually want is something (set of operations performed under that public key) which is readable like //Expected Output.

– Thanan_Jaje
Nov 15 '18 at 5:04













It seems that you can decode the transaction just fine, but your expectation makes no sense. xdr.Transaction has none of the fields shown in the expected output. Also Println produces the standard format for structs and that's not something resembling JavaScript.

– Peter
Nov 15 '18 at 9:37





It seems that you can decode the transaction just fine, but your expectation makes no sense. xdr.Transaction has none of the fields shown in the expected output. Also Println produces the standard format for structs and that's not something resembling JavaScript.

– Peter
Nov 15 '18 at 9:37












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275299%2fhow-to-decode-stellar-xdr%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275299%2fhow-to-decode-stellar-xdr%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Error while running script in elastic search , gateway timeout

Adding quotations to stringified JSON object values